Support » Theme: Twenty Twelve » Need help to add date and byline under title

Viewing 15 replies - 1 through 15 (of 15 total)
  • Michael


    Forum Moderator

    btw, the ‘new’ function in Twenty Twelve is called twentytwelve_entry_meta()
    you would just need to edit content.php in the child theme and move the call of that function from where it is now to just before <?php if ( comments_open() ) : ?> (untested)

    troubleshooting questions:

    does your code print anything?

    have you tried to remove the conditional statement to see if that helps?

    have you checked that the call is in an area that will be printed in the index page or single post?

    the function per-se seems to be ok, and is working without problems in my Twenty Twelve child test setup.

    Well, I did this with mine. In my child theme’s functions.php file, added:

    function mrh_posted_on() {
    	$date = sprintf( '<br />Posted on <a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>',
    		esc_url( get_permalink() ),
    		esc_attr( get_the_time() ),
    		esc_attr( get_the_date( 'c' ) ),
    		esc_html( get_the_date() )

    Then, in my child theme’s content.php in the header part I did:

    <header class="entry-header">
    			<?php // this was causing the featured image to show in the post: the_post_thumbnail(); ?>
    			<?php if ( is_single() ) : ?>
    			<h1 class="entry-title"><?php the_title(); ?></h1>
             <?php mrh_posted_on(); ?>
    			<?php else : ?>
    			<h1 class="entry-title">
    				<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'twentytwelve' ), the_title_attribute( 'echo=0' ) ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
             <?php mrh_posted_on(); ?>
    			<?php endif; // is_single() ?>
    			<?php if ( comments_open() ) : ?>
    				<div class="comments-link">
    					<?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'twentytwelve' ) . '</span>', __( '1 Reply', 'twentytwelve' ), __( '% Replies', 'twentytwelve' ) ); ?>
    				</div><!-- .comments-link -->
    			<?php endif; // comments_open() ?>
    		</header><!-- .entry-header -->

    Since I’m the Administrator on my blog with no Author’s I can’t really test the author bit (it never showed an author with the Twenty Eleven theme either). My guess is adding the author bit from Twenty Twelve’s twentytwelve_entry_meta() would allow that part to work.

    @alchymyth thanks for the help – I rechecked the call in content.php and it works only on my main page not on my posts. I had removed the conditional after I posted my question.

    Anyway you know of to get it to work on my single pages

    I looked at twentytwelve_entry_meta() but I didn’t want all the tags and categories at the top and my custom function appears even with one author so I don’t need to do the fake author work around. I didn’t see any info right now on how to filter the output to show just what I want.

    @markrh yes your function is similar to what I did and I did get it to show up on the main page but not on my single posts

    *UGH* never mind about it not showing up on posts – I didn’t catch the conditional for the title so I needed to put the call under both conditions like this:

    <?php if ( is_single() ) : ?>
    			<h1 class="entry-title"><?php the_title(); ?></h1>
    			<div class="entry-meta">
    									<?php abyline_posted_on(); ?>
    					</div><!-- .entry-meta -->
    			<?php else : ?>
    			<h1 class="entry-title">
    				<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'twentytwelve' ), the_title_attribute( 'echo=0' ) ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
    					<div class="entry-meta">
    						<?php abyline_posted_on(); ?>
    					</div><!-- .entry-meta -->
    			<?php endif; // is_single() ?>

    Yeah, if you notice in mine I had to put the call to my function in two places. One is for the main page and one for the single posts. I kinda made the same mistake you did the first time and only put it in once and it only worked on the main page.

    Yes MarkRH that is what tipped me off of something to check so thanks for that tip.

    The author doesn’t show up in the bottom meta area but does show up in my new byline function call

    Thanks again

    Hey guys,

    Is there any way you can explain as simply as possible what you did to get the author and date up at the top the way you did? I tried following your discussion but I don’t quite get it.

    I’m pretty much a simpleton when it comes to code and php.

    If you could tell me what .php files I need to move to my child folder and then exactly what code and where to put that code (very specifically or I’ll totally mess it up) to do what you did I would be very grateful!!!

    You need to put the function in your child function.php file and call the function from your child content.php file where it checks to see if it is a single post to decide how to display the title. You need to call it twice so the byline shows up on your main page and single posts

    Here is the code with notes on placement:

    Date and Byline until title

    The function is based on the one from the Twenty Eleven theme that WordPress took out in Twenty Twelve

    You can look up info on the function under the name it used in the Twenty Eleven theme: ‘twentyeleven_posted_on’

    Hey thanks for answering!

    However, I seemed to have messed it up somehow!

    I added the first chunk of code to the child functions.php – but I added it to the very bottom – was that correct?

    Then I inserted the call in the child content.php file. I only pasted in the code not the notes – so this is what I put in
    <?php abyline_posted_on(); ?>
    was that correct?

    When I went to my site it gives me this fatal error – so it looks like I messed up on my functions page.

    Fatal error: Cannot redeclare twentytwelve_setup() (previously declared in /hermes/bosweb/web148/b1487/ipg.nerdycriticscom/wp-content/themes/MyTwentyTwelve/functions.php:52) in /hermes/bosweb/web148/b1487/ipg.nerdycriticscom/wp-content/themes/twentytwelve/functions.php on line 77″



    Forum Moderator

    Did you copy the entire parent’s functions.php into the child’s folder? If so, delete it and start with a blank text file that just has <?php at the top.

    Sorry I’m a doofus! Think I fixed it thanks everyone!

    Working with the function file can be iffy. I’ve had issues with it in the past myself.

    Good to read you seem to have it working



    I’m trying to add a byline per this post but my theme doesn’t have a content.php. I use custom community theme. Is there another name perhaps?



    @ccarlow – this thread is about Twenty Twelve theme and it’s marked resolved. You can’t use code from one theme in another theme. Please start your own thread on the Custom Community Theme forum here:

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Need help to add date and byline under title’ is closed to new replies.