I'm displaying two posts on my main page, and using post pagination to go through the older posts.

My problem is I want to change the layout a bit of the most recent post. This sounds like a very basic question, and I have seen a lot of answers, but they only solve the problem for the first post on the page, not the actual -one and only- most recent post.

Right now I tried something like this:

<?php if(have_posts()):?>
   <?php $pcount = 0;?>
<?php endif;?>

<?php while (have_posts()): the_post(); ?>
   <?php $pcount++;?>
   <?php if($pcount < 2): ?>
       /*some html changes*/
   <?php endif; ?>
<? endwhile; ?>

This worked great. The first post on the page, which is by default the most recent one, has a changed layout. But when I navigate to the next page, I see the same. The first post (which is actually the third recent post, not the most recent), is also changed...

So, my actual question: How can I check if the post is actually the single most recent one. Not the first on the page.


2 Answers 2


$pcount is counting how many posts you've gone through in the current loop, it isn't counting the number of pages.

Think for a moment about what the loop is doing, if you're on page 2, why would you have the posts from page 1? It makes no sense, which is a sign that thinks aren't going to work.

If what you have was ever going to work then this:

while (have_posts()) {

Would print out the title of all the posts on page 2, and page 1. This is not what happens. The main loop code would need to have some kind of hint as to what your intentions were which it doesn't.

So your question is actually:

How do I determine the current page?

For which we can see an answer here:



$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

the conditional tag is_paged() can be used to limit the changes to the first of pages;

for example, change your conditional statement from:

   <?php if($pcount < 2): ?>


   <?php if($pcount < 2 && !is_paged() ): ?>
  • This works! Thank you. I accepted the other answer, because it goes a little more in depth. I would like to up vote your answer, but haven't got enough rep.
    – Decor
    Commented Mar 27, 2013 at 13:21
  • no problem - you are welcome ;-)
    – Michael
    Commented Mar 27, 2013 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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