Search code examples
phpwordpresswordpress-themingposts

If first post, style differently — Wordpress


I need the first post that was ever posted to be styled differently. Is there a way that I can see if the post is first, and then change its contents? I currently have a div in all my posts. This needs to be replaced with different div.

Apparently the following piece of code can help, but I'm not sure how to implemenet it:

<?php if (have_posts()) : $postCount = 1; while (have_posts()) : $postCount++; ?>

I'm new with WordPress so not entirely sure how this could work?


Solution

  • Append following codes after yours:

    <?php if (have_posts()) : $postCount = 1; while (have_posts()) : $postCount++; ?>
    
    <?php if($postCount == 2) { ?>
      // SOMETHING TO DO WITH FIRST POST
    <?php } else { ?>
      // SOMETHING TO DO WITH ALL OTHER POSTS
    <?php } ?>