Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // page totals
- $first_page_total= 5; // total number posts on first page
- $paginated_total = 20; // total number of posts on paginated pages
- // get the current category ID
- $current_category = get_query_var('cat');
- // pagination for custom page(s)
- if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
- elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
- else { $paged = 1; }
- $args1 = array(
- 'order' => 'DESC',
- 'post_status' => 'publish',
- 'cat' => $current_category,
- 'paged' => $paged
- );
- if(!is_paged()) {
- $args1['posts_per_page'] = $first_page_total;
- $args2 = array('cat' => $current_category,'offset' => $first_page_total, 'posts_per_page' => $paginated_total);
- $fake_query = new WP_Query( $args2 );
- $paginate_query = array('query' => $fake_query);
- wp_reset_postdata();
- $the_query = new WP_Query( $args1 );
- } else {
- $args1['posts_per_page'] = $paginated_total;
- $offset = $first_page_total + ($paginated_total*($paged-2));
- $args1['offset'] = $offset;
- $the_query = new WP_Query( $args1 );
- $paginate_query = array('query' => $the_query);
- }
- $found_posts = $paginate_query['query']->found_posts;
- //correct the max number of pages
- $pages = 0;
- for ($i=0; $i < $found_posts; $i += $paginated_total) {
- // first page
- if($i == 0){ $i = $first_page_total; ++$pages; }
- ++$pages;
- }
- $paginate_query['query']->max_num_pages = $pages;
- ?>
- <?php
- if ( $the_query->have_posts() ) :
- // pagenavi before the the loop
- wp_pagenavi($paginate_query);
- // Start of the Loop
- ?>
- <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
- <?php get_template_part('content', get_post_format()); ?>
- <?php endwhile; ?>
- <?php
- // pagenavi after the loop
- wp_pagenavi($paginate_query);
- ?>
- <?php else : ?>
- <h1 class="entry-title">Nothing Found</h1>
- <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement