Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

mrpolab on "Multiple loops and pagination"

$
0
0

Hi everybody,
are you ready for my strange help request?
ok, let's start.
I need to paginate my multiple loops shown on the home: the first loop contains 2 posts from one category (some sort of featured), the second loop 8 post from all the categories, but obv i don't whant the same article is shown twice in both loops.
I need the first loop to disappear from the non-first pages, so both in the home and only the second loop from the second page to the end.
This are the loops now:

<?php
// Let's fix pagination issue first

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

if(1 == $paged) {
}

$args=array(
	'post_type' => 'post',
	'post_status' => 'publish',
	'paged' => $paged,
	'post___in' => 'cat=32',
	'posts_per_page' => 2
);
$wp_query = new WP_Query('cat=32');
$wp_query->query($args);
?>
<?php if ( $wp_query->have_posts() ): while( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
	//First loop template here

	<?php endwhile; ?>

<?php
// Let's fix pagination issue first

if ( get_query_var('paged') ) {
	$paged = get_query_var('paged');
} elseif ( get_query_var('page') ) {
	$paged = get_query_var('page');
} else {
	$paged = 1;
}

$args=array(
	'post_type' => 'post',
	'post_status' => 'publish',
	'paged' => $paged,
	'post__not_in' => $do_not_duplicate,
	'posts_per_page' => 8
);
$wp_query = new WP_Query();
$wp_query->query($args);
?>
<?php if ( $wp_query->have_posts() ): while( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
// Secon loop template here
<?php endwhile; ?>
	<?php wp_reset_postdata(); ?>
<?php endif; ?>

	<?php if(function_exists('wp_pagenavi')): wp_pagenavi(); ?>
	<?php else: ?>
		<?php global $wp_query; if($wp_query->max_num_pages > 1) { ?>
		<div class="navigation clearfix">
			<span class="prev"><?php previous_posts_link( __('&larr; Previous', 'warrior') ); ?></span>
			<span class="next"><?php next_posts_link( __('Next &rarr;', 'warrior') ); ?></span>
		</div>
		<?php } ?>
	<?php endif; ?>
		<?php wp_reset_postdata(); ?>

<?php endif; ?>

Viewing all articles
Browse latest Browse all 8245

Trending Articles