Pagination for a custom loop
-
Hi,
Apologies if this topic has been covered but I’ve not had much luck in finding a working solution.
I’m using a custom loop to pull in various different custom post types and I have it set up to add different classes to the first post on the front page, like so…
<?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('page') ) ? get_query_var('page') : 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 push--bottom <?php if(!is_paged() && ($counter==0)) { echo 'xsmall-12 featured-article'; $counter++; } else { echo 'xsmall-12 small-6 article-preview'; } ?> ">
That’s all of my code before the actual content. I have tried the suggested pagination options on the WordPress codex and can’t seem to get it work. The one I’ve tried out is this…
<?php //Protect against arbitrary paged values $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; $args = array( 'posts_per_page' => 5, 'category_name' => 'gallery', 'paged' => $paged, ); $the_query = new WP_Query( $args ); ?>
But it either break the loop entirely or does nothing, depending on where I place it.
Any pointers would be much appreciated!
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘Pagination for a custom loop’ is closed to new replies.