I have a custom post archive I have two loops. The first loop displays only the most recent of the post type in a large container. The second loop displays posts in a grid of small containers. When I go to page two, the larger container is still there, although the smaller ones accurately show up below. What I would like is to find a way for the large container to not show up on any page past 1. I don't know if this is possible with code or if I'd have to find some tricky way to do it with another template. Below is my simplified code:
<?php $my_query = new WP_Query('post_type=nmr&posts_per_page=1');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID; ?>
<div id="nmr-big">
<?php the_post_thumbnail('full'); ?>
</div>
<?php endwhile; ?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('post_type=nmr&showposts=5&paged='.$paged);
if (have_posts()):
while (have_posts()):
the_post();
if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts);
?>
<div class="nmr-small">
<?php the_post_thumbnail('post-thumb'); ?>
</div>
<?php endwhile; endif; ?>
<?php if(function_exists('wp_page_numbers')) { wp_page_numbers(); } ?>
Thanks!
Caroline Keim answers:
This should work -
<?php
$page = get_query_var('page');
if ($page < 2) { ?>
Your larger featured post you only want on page 1
<?php } ?>
The 2nd loop
Jeremy Phillips comments:
When I tried it like below it didn't work. Would that be correct?:
<?php
$page = get_query_var('page');
if ($page < 2) { ?>
<?php $my_query = new WP_Query('post_type=nmr&posts_per_page=1');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID; ?>
<div id="nmr-big">
<?php the_post_thumbnail('full'); ?>
</div>
<?php endwhile; ?>
<?php } ?>
//second loop
Jeremy Phillips comments:
Well, with a little tweaking I got your code to work like so:
<?php
if( get_query_var('paged') < 2 ) { ?>
//First loop
<?php } ?>
//Second loop
Nice and compact! Thanks!
Hameedullah Khan answers:
Try the following code:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
if ( $paged < 2 )
{
// This is not a paginated page (or it's simply the first page of a paginated page/post)
$my_query = new WP_Query('post_type=nmr&posts_per_page=1');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID; ?>
<div id="nmr-big">
<?php the_post_thumbnail('full'); ?>
</div>
<?php endwhile; ?>
<?php
}
else
{
// This is a paginated page.
query_posts('post_type=nmr&showposts=5&paged='.$paged);
if (have_posts()):
while (have_posts()):
the_post();
if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts);
?>
<div class="nmr-small">
<?php the_post_thumbnail('post-thumb'); ?>
</div>
<?php endwhile; endif;
} // endif $paged
?>
<?php if(function_exists('wp_page_numbers')) { wp_page_numbers(); } ?>
Jeremy Phillips comments:
I have carefully gone through your code ( which looks good) but won't work. I'm currently working on a production server and it won't tell me what line the error is on. If you have an idea of what may be wrong let me know, otherwise I will test this on a different server a bit later. Thanks!
Hameedullah Khan comments:
I just tested it, this doesn't have any syntax error so it should work. Did you get any error or blank page when you use this code? This is actually your code I just have wrapped it in following if clause.
if ($paged <2) {
} else {
}
Jeremy Phillips comments:
Ok, I was able to get it to run with no errors this time, although, the first loop is fine, but the second loop doesn't appear.
derekshirk answers:
Replace your query with this:
<?php
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('post_type=nmr'.'&paged='.$paged);
?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>