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 🙂
Awesome post! Keep up the great work! 🙂
Thanks dude .. thanks alot 🙂
Great content! Super high-quality! Keep it up! 🙂
Thanks @AffiliateLabz for you feedback.. I’m glad it helped you 😊