Pagination for custom post in wordpress

pagination for custom post type wordrpess

Here is how to implement Pagination for custom posts in wordpress.

Add this to functions.php


function pagination_bar() {
    global $wp_query;
 
    $total_pages = $wp_query->max_num_pages;
 
    if ($total_pages > 1){
        $current_page = max(1, get_query_var('paged'));
 
        echo paginate_links(array(
            'base' => get_pagenum_link(1) . '%_%',
            'format' => 'page/%#%',
            'current' => $current_page,
            'total' => $total_pages,
        ));
    }
}

Add this to page


<div class="row">
              <?php 
	$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
      query_posts(array( 

        'post_type' => 'post',

        'showposts' => 4,
		'paged' => $paged

		

    ) );  

?>
              <?php while (have_posts()) : the_post(); ?>
              <div class="col-sm-6">
                <div class="tab-1"> <a href="<?php echo get_permalink(); ?>">
                  <?php the_post_thumbnail(); ?>
                  </a>
                  <h3>
                    <?php the_title();?>
                  </h3>
                  <p>
                    <?php the_excerpt();?>
                  </p>
                </div>
                <!--tab-1 --> 
                
              </div>
              <!--col-sm-6 -->
              
              <?php endwhile;?>
              
              <nav class="pagination hm">
        <?php pagination_bar(); ?>
      </nav>
            </div>

I hope this helps you .. Thanks 🙂

If this help you then.. Can you buy a Cup of Coffee for me by nst webcreation paypal--OR-- nst webcreation blog coffee cup

Published by

NST

Myself Narender Singh Thakur ( NST ) and i share my Experience/Knowledge and Tricks for folks and beginners to solve their issues while making websites through this Planet.

Related Articles

4 thoughts on “Pagination for custom post in wordpress”

Leave a Reply

Your email address will not be published. Required fields are marked *

Click to Chat