• Does anyone know if it’s possible to test whether or not a particular post is one of the latest two posts on the blog?

    The reason I ask is because I’d like to display a certain image on only my first two posts…I just don’t know how to test for that condition.

    Thanks so much for your help.

Viewing 1 replies (of 1 total)
  • The code below shows how to get the IDs of the top two posts into an array and use if (in_array($post->ID)) in the loop to test if a post is one of the top two.

    <?php
    $mytopposts = get_posts('caller_get_posts=1&showposts=2');
    $postids = array();
    foreach ($mytopposts as $toppost) {
      $postids[] = $toppost->ID;
    }
    $args = array(
      'posts_per_page' => 10,
    );
    query_posts($args);
    if (have_posts()) {
       while (have_posts()) {
         the_post();
         echo '<h2>'; the_title(); echo '</h2>';
         if (in_array($post->ID,$postids)) {
           echo "<p>This one is a Top Post</p>";
         }
       }
    }
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘How to test for the two latest posts?’ is closed to new replies.