Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've got a multi-author site running on Wordpress 3.1.3 .

I'm trying to place an extra header above the title for a specific author. So if "John" posts on the blog, it would have an above the post on the home page that says "John's Perpective", or something of that nature. The idea is that we want one of the many author's posts to be highlighted for users.

My issue is that I cannot figure out how to check for which user wrote the post within the loop. I am doing it on various other areas of the site via WP_Query.

I'm imagining I need something like this (pseudo code):

if ( author == 2 ) {
    echo '<h2>John's Perspective</h2>'
}

Should be an easy fix, but I'm stumped.

Thanks in advance!

share|improve this question

3 Answers 3

up vote 0 down vote accepted

When you're in the loop, you can use get_the_author() to get the author's 'Public' name. Alternatively, you can use get_the_author_meta( 'ID' ) in the loop to get the author ID.

So, modifying your psuedo-code:

if ( 2 == get_the_author_meta( 'ID' ) ) {
    echo '<h2>John's Perspective</h2>'
}
share|improve this answer
    
Thanks a lot! I ended up using this solution because I like IDing the authors by ID instead of name. –  John Sheridan Jun 22 '11 at 19:19

You can use get_the_author() (Codex ref), which returns the author's display name. e.g.:

if ( 'John Smith' == get_the_author() ) {
    // This is a post written by John; do something
}

To use other author metadata, use get_the_author_meta() (Codex ref), e.g.:

$authormeta = get_the_author_meta();

if ( 'johnsmith' == $authormeta->user_nicename ) {
    // This is a post writeen by username 'johnsmith'; do something
}
share|improve this answer
    
Thanks for the input Chip! This worked as well. –  John Sheridan Jun 22 '11 at 19:19

if you want to show a bit more than the name of the author, there is this function in twentyten that you might want to use:

    <?php if ( get_the_author_meta( 'description' ) ) : // If a user has filled out their description, show a bio on their entries  ?>
<div id="entry-author-info">
    <div id="author-avatar">
        <?php echo get_avatar( get_the_author_meta( 'user_email' ), apply_filters( 'twentyten_author_bio_avatar_size', 60 ) ); ?>
    </div><!-- #author-avatar -->
    <div id="author-description">
        <h2><?php printf( esc_attr__( 'About %s', 'twentyten' ), get_the_author() ); ?></h2>
        <?php the_author_meta( 'description' ); ?>
        <div id="author-link">
            <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>">
                <?php printf( __( 'View all posts by %s <span class="meta-nav">&rarr;</span>', 'twentyten' ), get_the_author() ); ?>
            </a>
        </div><!-- #author-link -->
    </div><!-- #author-description -->
</div><!-- #entry-author-info -->
<?php endif; ?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.