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 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!

share|improve this question
    
Have you tried using get_query_vars( 'paged' )? –  m0r7if3r Feb 19 '12 at 18:31
    
It's get_query_var() <- singular :) –  kaiser Feb 19 '12 at 20:03

3 Answers 3

up vote 0 down vote accepted

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:

<?php 
 //initialize $do_not_duplicate
 $do_not_duplicate=0;
 //is_paged returns true if we are on page 2,3,...
 if(!is_paged()):
      //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...
      endwhile;
 endif;

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

Not tested

share|improve this answer
    
That does work, thanks! Can I force WP to use a different template for the second page? –  Jannemans 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
endif;

I think that'll do the trick for you.

share|improve this answer

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
}
share|improve this answer

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.