[resolved] [theme: twentytwelve] Help with date coding and styling (6 posts)

  1. jessica
    Posted 3 years ago #


    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>
       <?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!

  2. jessica
    Posted 3 years ago #

    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.


  3. bcworkz
    Posted 3 years ago #

    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.

  4. jessica
    Posted 3 years ago #

    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?

  5. Michael
    Forum Moderator
    Posted 3 years ago #

    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.

  6. jessica
    Posted 3 years ago #

    Thanks - fixed the class in content-page.php

Topic Closed

This topic has been closed to new replies.

About this Topic