• Resolved thetoolman123

    (@thetoolman123)


    Hi there,

    I am trying to add numbered pagination under my blog feed with the below code, but it’s not displaying the pagination.

    Can anyone see what I have wrong?

    Thanks

    
    <section class="container feed">
    <div class="row">
    	<?php $args = array(
    	'base'               => '%_%',
    	'format'             => '?paged=%#%',
    	'total'              => 1,
    	'current'            => 0,
    	'show_all'           => false,
    	'end_size'           => 1,
    	'mid_size'           => 2,
    	'prev_next'          => true,
    	'prev_text'          => __('? Previous'),
    	'next_text'          => __('Next ?'),
    	'type'               => 'plain',
    	'add_args'           => false,
    	'add_fragment'       => '',
    	'before_page_number' => '',
    	'after_page_number'  => ''
    ); ?>
    	
    <?php
    		if ( have_posts() ) :
    
    			if ( is_home() && ! is_front_page() ) : ?>
    				<header>
    					<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
    				</header>
    
    			<?php
    			endif;
    
    			/* Start the Loop */
    			while ( have_posts() ) : the_post();
    
    				/*
    				 * Include the Post-Format-specific template for the content.
    				 * If you want to override this in a child theme, then include a file
    				 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
    				 */
    				get_template_part( 'template-parts/content', get_post_format() );
    
    			endwhile;
    
    			the_posts_navigation();
    
    		else :
    
    			get_template_part( 'template-parts/content', 'none' );
    
    		endif; ?>
    	
    </div>
    <?php echo paginate_links( $args ); ?>
    </section>
Viewing 3 replies - 1 through 3 (of 3 total)
  • You have the_posts_navigation(), which with default args gives you “Prev” and “Next” style links. Then you have paginate_links( $args ), which is the older function and is used for when you make your own queries. The args look conflicting.
    Instead you should just use something like the_posts_pagination( 'mid_size=2' ); and remove the two you have.

    Hello,
    I think this code is working.

    <section class="container feed">
    	<div class="row">
    		<?php 
    		$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : '1';
    		$args = array(  
    			'post_type' => 'post',
    			'posts_per_page'         => '3',
    			'paged'                  => $paged
    		);
    		query_posts( $args );
    		$posts= get_posts( $args );
    		if ($posts) {
    			?>
    			<header>
    				<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
    			</header>
    			<?php
    		    foreach ( $posts as $post ) {
    		    	get_template_part( 'template-parts/content', get_post_format() );
    		    }
    		    the_posts_pagination( array(
    		    	'mid_size'=>3,
    			 	'prev_text' => _( '? Previous'),
    			  	'next_text' => _( 'Next ?'),
    			) );
    		}
    		else{
    			echo '<p>No post found..</p>';
    		}
    		?>
    	</div>
    </section>
    • This reply was modified 6 years, 4 months ago by angelch.
    • This reply was modified 6 years, 4 months ago by bcworkz. Reason: code fixed
    Thread Starter thetoolman123

    (@thetoolman123)

    Hi there,

    Thank you very much, that worked ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Pagination with numbers’ is closed to new replies.