I have a index.php with a featured post and a number of other posts and the standard wp_pagenavi at the bottom.

I'm using the 2 loops from the wordpress codex like this:

<?php $my_query = new WP_Query('category_name=featured&posts_per_page=1');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID;?>
  <!-- Do stuff... -->
<?php endwhile; ?>
  <!-- Do other stuff... -->
<?php if (have_posts()) : while (have_posts()) : the_post(); 
if( $post->ID == $do_not_duplicate ) continue; ?>
 <!-- Do stuff... -->
<?php endwhile; endif; ?>

If I've read the theme hierarchy correctly, an archive.php page should be used when clicking "Previous" in the pagination section... (correct?)

However, this is not the case, clicking previous is showing me a page with the same layout as my index.php and thus with the same featured post. (pagination on the other posts does work though)

I've been messing around with is_paged but haven't been able to get it working... Thanks for the help!

  • Have you tried using get_query_vars( 'paged' )? – mor7ifer Feb 19 '12 at 18:31
  • It's get_query_var() <- singular :) – kaiser Feb 19 '12 at 20:03

In short no - the template used is based on the query, and when paginating you are essentially repeating the same query, but for a different page. In general the template will be the same.

archive.php can be used for most queries, but often preferable templates exist (e.g. category templates, tag templates, author templates etc.). What is preferable is determined by the template hierarchy. For the home page,however, index.php is often used, and the template will persist with pagination.

As for displaying only something on 'page 1', you can try the following:

 //initialize $do_not_duplicate
 //is_paged returns true if we are on page 2,3,...
      //Get featured content for page 1
      $my_query = new WP_Query('category_name=featured&posts_per_page=1');
      while ($my_query->have_posts()) : $my_query->the_post();
           $do_not_duplicate = $post->ID;
           //Do stuff...

 //Display rest of content
 if (have_posts()) : 
    while (have_posts()) : the_post(); 
         if( $post->ID == $do_not_duplicate ) continue;
         //Do stuff

Not tested

  • That does work, thanks! Can I force WP to use a different template for the second page? – Jan Henckens Feb 19 '12 at 18:48
  • It's possible I suppose... not sure of the best way to achieve it though, but this would make a good question :D. Also don't forget to click the tick next to answer that solves your problem - it takes it off the unanswered pile and means other can quickly see what worked for you. – Stephen Harris Feb 19 '12 at 20:37

is_paged is just a boolean function for if the list has multiple pages or not.

What you need is: $wp_query->query_vars['paged']. Surround your featured post code with,

global $wp_query;
if ( !isset($wp_query->query_vars['paged']) || $wp_query->query_vars['paged'] == 1 ) :
# Featured post code

I think that'll do the trick for you.


Easy: WP got a lot on board for this. No direct array/object access needed.

// Before the loop
$paged = get_query_var( 'paged' );

// In the loop
if ( 
    ( ! isset( $paged )  OR ! $paged )
    AND is_sticky( get_the_ID() )
    // do stuff

Add this conditional statement in your custom function.

if ( is_home() && get_query_var( 'paged' ) >= 2 ) 
  • You can simply do if ( is_home() && !is_paged() ) – Pieter Goosen Apr 1 '15 at 5:17
  • Yes but my code is more flexible. – Brad Dalton Apr 2 '15 at 7:55
  • Did you test your code? – Brad Dalton Apr 2 '15 at 8:09
  • No, I did not, but looking logically at it, it should work. !is_paged() should return true on page 1, aftr that it should return false. So, anything inside that conditional should execute on page one in your homepage, and not execute in any other page :-) – Pieter Goosen Apr 2 '15 at 8:16
  • I don't think your code will work as it applies to all paginated pages rather than the 1st page of a paginated archive. My code does not effect the 2nd and subsequent pages for the home page archive. – Brad Dalton Apr 2 '15 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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