Support » Themes and Templates » [theme: twentytwelve] Help with date coding and styling

  • Resolved jessica

    (@kerflop)


    Hello,

    I’m trying to figure out how to get the date to show up to the left of the post title, styled a certain way. I got this to work on a genesis theme, but I’m new to twentytwelve and can’t quite seem to sort it out.

    Here’s the code in a genesis (prose) theme that worked nicely before:

    add_action( 'genesis_before_post_title', 'child_before_post_title' );
    function child_before_post_title() {
       if ( ! is_page() ) { ?>
    
       <div class="entry-meta">
            <span class='day'><?php the_time('j');?></span>
             <span class='month'><br/><?php the_time('M'); ?></span>
         </div>
    
       <?php }
    }

    That, with some CSS of course, resulted in this: http://elevensixty.com/date-comment.png (minus the comment stuff which I did elsewhere). The code also made sure the date only showed on post pages, not static pages where it wasn’t needed.

    In twentytwelve, I am trying to accomplish something similar. Here is a screen capture from the PSD file to show you what I’m aiming for: http://elevensixty.com/date.png

    I believe I need help with the action part, I’m not sure what the right code is.

    Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter jessica

    (@kerflop)

    Sorry for the duplicate, I found it — I was trying to click on the ‘edit’ link under my name and it went nowhere, so I thought I’d messed up.

    Anyway, I came up with a bandaid solution for this, by creating a new content.php file for my child theme and posting the entry-meta code in there. Then using absolute positioning with a margin padding the entry title.

    However, if anyone has a more elegant solution using the functions file, I’m all ears.

    Thanks!

    Moderator bcworkz

    (@bcworkz)

    I would say altering child theme templates is a perfectly proper solution. This is why child theme functionality was added. Utilizing hooks is more for the benefit of plugin authors who do not have access to theme resources.

    Thread Starter jessica

    (@kerflop)

    That’s what I previously thought, and then had a developer yell at me for not using the functions file, so I was worried it was more of a ‘hack’ than an elegant solution.

    Anyway, the issue I’m having with this solution, is it removes the ability to add the if statement that only made the styling appear on the posts.

    if ( ! is_page() ) { ?>

    So my design tampering causes issues on the static pages where the date doesn’t appear. Any ideas for a solution to this?

    So my design tampering causes issues on the static pages where the date doesn’t appear.

    Twenty Twelve uses content.php for index, archive, and single posts; and content-page.php for static pages.

    Thread Starter jessica

    (@kerflop)

    Thanks – fixed the class in content-page.php

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[theme: twentytwelve] Help with date coding and styling’ is closed to new replies.