printf and comments_number() order (3 posts)

  1. bzmillerboy
    Posted 5 years ago #

    I'm customizing the starkers theme which re-uses a lot of the twentyten functions. I'd like to display the post meta data using this modified twentyten_posted_on() function.

    function twentyten_posted_on() {
    	printf( __( '%2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
    			'meta-prep meta-prep-author',
    			sprintf( '<span class="entry-date">%3$s</span>',
    				esc_attr( get_the_time() ),
    			sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
    				( get_the_author_meta( 'ID' ) ),
    				sprintf( esc_attr__( 'View all posts by %s', 'twentyten' ), get_the_author() ),
    			sprintf( '<span>%1$s</span>',
    				comments_number('No Comments', '1 Comment', '% Comments')

    For some reason it's outputs "No CommentsOctober 6, 2010 by bzmillerboy" instead of "October 6, 2010 by bzmillerboy No Comments".

    I finally had to pull the comments_numbers out of the functions.php and put it after the function on the single.php, like this.

    <?php twentyten_posted_on(); ?> <?php comments_number('No Comments', '1 Comment', '% Comments') ?>

    Any suggestions on how to get this to work within the function?

  2. bzmillerboy
    Posted 5 years ago #

    It at least is outputing everything, but I can't figure out why it's not in the right order.

    I have a feeling it is similar to this issue, but still don't understand.


  3. Michael
    Forum Moderator
    Posted 5 years ago #

    yes, it is related:


    comments_number() outputs the result; in your context you need to use get_comments_number()
    with the added complications

    and you also need to use this as the fourth variable for you printf:

    something like:
    printf( __( '%2$s <span class="meta-sep">by</span> %3$s, %4$s', 'twentyten' ),

Topic Closed

This topic has been closed to new replies.

About this Topic