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 need to display an avatar in the post info position which i have written the code for but i only want to display it on the most recent post on the home page and not a specific post as this will change when a new post id published.

Couldn't find a conditional tag which handles this.

I'm using the code in a custom function with genesis_hook in the child theme.

function latest_post_author_avatars() {
if (is_single() || is_home() ) {  
echo get_avatar(get_the_author_id(), 40);

  }

}
add_action('genesis_after_post_title', 'latest_post_author_avatars');

// Here's the final solution which works. Thanks to both of you.

function latest_post_author_avatars() {
global $wp_query;
if (is_single() || is_home() && 0 === $wp_query->current_post)  {
echo get_avatar(get_the_author_id(), 40);

  }

}
add_action('genesis_after_post_title', 'latest_post_author_avatars');
share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

Within an ordinary WordPress Loop, the following would identify the first post in the Loop, which would be the latest if posts are ordered by date descending.

global $wp_query; // might not be necessary; depends on context
if (is_paged() && 0 === $wp_query->current_post) {
  echo 'first-post';
}

I don't know how your custom function works as you didn't post any code and I don't how genesis_hook works as I don't use Genesis, but hopefully that will help.

share|improve this answer
1  
hehe, you beat me to it, it looks like I posted similar idea 5 seconds after you ;-) –  birgire Jun 3 '13 at 13:29
    
@birgire : So it goes, right? Good answer though :) –  s_ha_dum Jun 3 '13 at 13:29
    
I vote +1 for you, since you posted before me ;-) –  birgire Jun 3 '13 at 13:33
add comment

Here is one idea for a template tag to check for the first post:

function is_first(){
    global $wp_query;

    if( 0 === $wp_query->current_post  && 0 === get_query_var('paged') )
        return true;

    return false;
}

This should return true if the post position is 0 (according to $wp_query) and the we are on the first page of paged.

You might have to adjust this to your needs.

share|improve this answer
add comment

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.