• Resolved shields

    (@shields)


    I am using Twenty-Eleven and while the date and author of each post used to show up, it doesn’t with this theme.

    Is there a way to make it show up under the post title?

    I’ve searched and googled, but come up empty.

    Thanks.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Do not edit the Twenty Eleven theme. It is the default WordPress theme and having access to an unedited version of the theme is vital when dealing with a range of site issues. Create a child theme for your changes.

    Make a post as another user.

    If I’m not mistaken, 2011 adds the class single-author to the body if only one author is posting. In the css, by-author is hidden for single author blogs.

    So, we can make a child theme, as @esmi suggested, to modify this behaviour, or make a single post as another author as the easy out

    Thread Starter shields

    (@shields)

    Thanks. I already am using a child theme. I just don’t know what to modify in that theme to get it to show the TIME and AUTHOR.

    I will Rev. Voodoo’s suggestion, but I’d really like to know the rest of esmi’s thinking. What file to I mod in my child theme and how do I modify it?

    Thanks again.

    Man… my last post got lost somehow.

    Anyway, you can modify the twentyeleven_posted_on function which exists at the bottom of functions.php

    OR

    you can filter the addition of the single-author body class

    Those are the last 2 functions in 2011 functions.php, and you would do it through your child functions.php

    Thread Starter shields

    (@shields)

    So, Good Rev, let me see if I have this right.

    I want to create a file called functions.php that has ONLY this text in it:

    if ( ! function_exists( 'twentyeleven_posted_on' ) ) :
    /**
     * Prints HTML with meta information for the current post-date/time and author.
     * Create your own twentyeleven_posted_on to override in a child theme
     *
     * @since Twenty Eleven 1.0
     */
    function twentyeleven_posted_on() {
    	printf( __( '<span class="sep">Posted on </span><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s" pubdate>%4$s</time></a><span class="by-author"> <span class="sep"> by </span> <span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'twentyeleven' ),
    		esc_url( get_permalink() ),
    		esc_attr( get_the_time() ),
    		esc_attr( get_the_date( 'c' ) ),
    		esc_html( get_the_date() ),
    		esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    		esc_attr( sprintf( __( 'View all posts by %s', 'twentyeleven' ), get_the_author() ) ),
    		get_the_author()
    	);
    }
    endif;

    and put it in my twentyeleven-child folder?

    That’s it?

    Thread Starter shields

    (@shields)

    I fixed this.

    I had this in my style.css file.

    .entry-meta {
    clear: both;
    color: #666666;
    display: none;
    font-size: 12px;
    line-height: 18px;
    }

    When I commented it out, it fixed it.

    Thanks for running this rabbit-trail with me.

    Yup, that’ll do it too! To answer your above question, just for the sake of learning…. in case you want to know this in the future… you can copy a function from parent to child, IF it is wrapped in a

    if ( ! function_exists( 'twentyeleven_posted_on' ) ) :

    check. This check tells 2011 to use the function in the parent theme IF it doesn’t exist in the child…. so you can put this portion:

    function twentyeleven_posted_on() {
    	printf( __( '<span class="sep">Posted on </span><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s" pubdate>%4$s</time></a><span class="by-author"> <span class="sep"> by </span> <span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'twentyeleven' ),
    		esc_url( get_permalink() ),
    		esc_attr( get_the_time() ),
    		esc_attr( get_the_date( 'c' ) ),
    		esc_html( get_the_date() ),
    		esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    		esc_attr( sprintf( __( 'View all posts by %s', 'twentyeleven' ), get_the_author() ) ),
    		get_the_author()
    	);
    }

    into a child theme, and then edit it as you see fit. And your child theme edited function would be used in place of the parent theme function.

    This only works for functions with that ! function_exists portion. If the function in the parent theme doesn’t have that check, you can’t just copy it to your child theme. That’ll crash your site.

    Hope that isn’t too confusing. I know you don’t need this info anymore, but I didn’t want to leave ya hangin!

    Also, if you ever do make a functions.php for a child theme… remember the very first thing in that file, above any code, must be

    <?php

    Always gotta have that opening php tag at the top of the file

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How do you add the Date and Author in Posts in Twenty-Eleven?’ is closed to new replies.