WordPress.org

Ready to get started?Download WordPress

Forums

printf and comments_number() order (3 posts)

  1. bzmillerboy
    Member
    Posted 3 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>',
    				get_permalink(),
    				esc_attr( get_the_time() ),
    				get_the_date()
    			),
    			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() ),
    				get_the_author()
    			),
    			sprintf( '<span>%1$s</span>',
    				comments_number('No Comments', '1 Comment', '% Comments')
    			)
    	);
    }
    endif;

    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
    Member
    Posted 3 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.

    http://wordpress.org/support/topic/printf-weirdness-with-comment_author_link

  3. alchymyth
    Forum Moderator
    Posted 3 years ago #

    yes, it is related:

    http://codex.wordpress.org/Function_Reference/comments_number

    comments_number() outputs the result; in your context you need to use get_comments_number()
    http://codex.wordpress.org/Template_Tags/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