HOME / BLOG / BLOG-POST

How to use pagination in wp_query in wordpress ?

Use pagination in wp_query in wordpress

Best Way of getting pagination in wp_query is –

<?php 
$paged = get_query_var('paged');
$args = array(
'cat' => 1,
'posts_per_page' => 5,
'paged' => $paged,
);

$bolly_post = new WP_Query($args);
if ( $bolly_post->have_posts() ) :  
while ( $bolly_post->have_posts() ) : $bolly_post->the_post(); ?>
<a href="<?php echo get_the_permalink(get_the_ID())?>"><?php echo the_post_thumbnail()?></a>
<p class="p-title"><a href="<?php echo get_the_permalink(get_the_ID())?>"><?php  the_title(); echo " | Uploded By:" . get_the_author();?></a>
 <?php	endwhile;  ?>
<div class="row mp pagination" style="margin-top:20px;" >
<?php echo paginate_links(array(
'total' => $bolly_post->max_num_pages
)
); ?>
</div>

OR you can use another way by using WP-PageNavi plugin

/* just install and active the plugin and then paste this code in
 place of above one  */
<div class="row mp pagination" style="margin-top:20px;" >
<?php wp_pagenavi(
array(
'query' => $bolly_post,
)
);
?>
</div>

 


about authors

Sandip Das

Web Developer

Once a legend said “Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” – Martin Fowler.



POST COMMENTS

Leave a Reply

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