Pagination returning same posts on each page
-
Hi,
So I have a custom loop for my front page that returns 11 posts on the first page with the first one carrying additional classes, and subsequent pages show 10 posts with the same classes. I have added pagination to this loop and while it changes page, the posts it returns are the same as the first page.
This is my loop currently…
<?php $first_page_post_count = 11; $subsequent_pages_post_count = 10; $paged = $paged ? $paged : 1; if($paged > 1){ // not first page $posts_per_page = $subsequent_pages_post_count; if($paged == 2){ // second page $offset = $first_page_post_count; } else { // subsequent pages $offset = $first_page_post_count + ($subsequent_pages_post_count * ($paged - 2)); } } else { // first page $offset = 0; $posts_per_page = $first_page_post_count; } $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $query_args = array( 'post_type' => array ('post' , 'reviews' , 'trailer' , 'feature'), 'posts_per_page' => $posts_per_page, 'offset' => $offset, 'paged' => $paged ); $the_query = new WP_Query( $query_args ); ?> <?php $counter = 0; if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <div class="col <?php if(!is_paged() && ($counter==0)) { echo 'xsmall-12 featured-article'; $counter++; } else { echo 'xsmall-12 small-6 article-preview'; } ?> "> //content </div> <?php $counter++; if ($counter % 2 == 0) { //content } endwhile; ?> <?php else: ?> //content <?php endif; ?>
My pagination function looks like this…
function pagination($pages = '', $range = 4) { $showitems = ($range * 2)+1; global $paged; if(empty($paged)) $paged = 1; if($pages == '') { global $wp_query; $pages = $wp_query->max_num_pages; if(!$pages) { $pages = 1; } } if(1 != $pages) { echo "<div class=\"nav-links\">"; //if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>« First</a>"; echo "<a class='page-numbers prev' href='".get_pagenum_link($paged - 1)."'><i class='icon icon-angle-left'></i></a>"; for ($i=1; $i <= $pages; $i++) { if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) { echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class='page-numbers'>".$i."</a>"; } } if ($paged < $pages && $showitems < $pages) echo "<a class='page-numbers next' href=\"".get_pagenum_link($paged + 1)."\"><i class='icon icon-angle-right'></i></a>"; //if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last »</a>"; echo "</div>\n"; } }
The pagination works on every other page and I have tried removing the counter, offset etc. from the front page but the pagination still does the same thing. Any guidance on this would be much appreciated.
Viewing 13 replies - 1 through 13 (of 13 total)
Viewing 13 replies - 1 through 13 (of 13 total)
- The topic ‘Pagination returning same posts on each page’ is closed to new replies.