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!
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:
Not tested
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,I think that’ll do the trick for you.
Easy: WP got a lot on board for this. No direct array/object access needed.
Add this conditional statement in your custom function.