• I am having troubles getting pagination to work with a page template. The goal of this code is to have a category news page that will place a featured article at the beginning of the news feed.

    The way it must function is articles marked as the category AND marked as featured appear at the start of the page, the remainder of the posts just marked category appear below and should be paginated. This may be a result of calling 2 WP_Query’s, but am unsure as to how to accomplish this otherwise.

    Here is what I have tried:

    • I have tried the WP-PageNavi with no success
    • I have tried using get_query_var(‘paged’); and get_query_var(‘page’);
    • I have tried wp_reset_postdata();

    In an optimum world I would like it to display pagination as:
    Prev | 1 2 3 | Next

    The page should display the number of articles set under wordpress >settings>general>reading (if that’s possible, otherwise it may be set in the template)

    Articles should not be repeated, and the featured articles should only appear on the first page. I have removed the following code till I can get pagination working:
    $do_not_duplicate = $post->ID;

    This wraps the featured articles loop
    <?php if(!is_paged()): // Don't display featured content if you are within pagination as to not repeat posts ?>

    Please excuse the code I am new to both php and wordpress

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
    
    <div class="post">
    
    <?php
    	$args = array(
    		'category__and' => array(7,6),
    		'paged' => get_query_var('paged')
    	);
    	$posts_query = new WP_Query($args);
    ?>
    
    <?php if( $posts_query->have_posts() ) : while( $posts_query->have_posts() ) : $posts_query->the_post(); ?>
    
    	<?php get_template_part( 'content-post-featured', get_post_format() ); ?>
    
    	<?php endwhile; // end of the loop. ?>
    
    	<?php endif; ?>
    
    </div>
    
    <div class="post">
    
    <?php
    	$args = array(
    		'cat' => 7,
    		'category__not_in' => array(6),
    		'paged' => get_query_var('paged')
    	);
    	$posts_query = new WP_Query($args);
    ?>
    
    <?php if( $posts_query->have_posts() ) : while( $posts_query->have_posts() ) : $posts_query->the_post(); ?>
    
    	<?php get_template_part( 'content-post-standard', get_post_format() ); ?>
    
    	<?php endwhile; // end of the loop. ?>
    
    	<?php endif; ?>
    
    </div>
    
    <div id="postnavi">
    <?php posts_nav_link(); ?>
    </div>

    It’s simply not returning pagination at all.. please help me.

    Thanks!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Pagination Issues’ is closed to new replies.