Hari Shankar
asked on
Wordpress Pagination Function Not working ?
Hi Experts,
Am trying to create a custom page in wordpress that will show the post . But when i give the pagination previous_posts_link() ; and next_posts_link( ); it doesn't work . Please see the below code
Am trying to create a custom page in wordpress that will show the post . But when i give the pagination previous_posts_link() ; and next_posts_link( ); it doesn't work . Please see the below code
<?php if (have_posts()) :?>
<?php $custom_query = new WP_Query('cat=2'); // exclude category 9
while($custom_query->have_posts()) : $custom_query->the_post(); ?>
<div class="col-md-12 post-holder">
<div class="well-box">
<div class="post-image"><a href="#"><img src="<?php the_post_thumbnail( '', array('class' => 'img-responsive'));?>"</a></div>
<h1 class="post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<div class="post-meta"> <span class="date-meta">ON <a href="#"><?php the_date(); ?></a> /</span> <span class="admin-meta">BY <a href="#"><?php the_author(); ?></a> /</span> <span class="tag-meta">IN <a href="#"><?php the_tags(); ?></a> /</span> <span class="comment-meta"><?php comments_number('No','1','%'); ?> <a href="#">Comments</a></span> </div>
<p> <?php the_excerpt(); ?></p>
</div>
</div>
<!-- /.blog holder -->
<?php endwhile; ?>
<?php wp_reset_postdata(); // reset the query ?>
<!-- /.blog holder -->
<div class="col-md-12 tp-pagination">
<ul class="pagination">
<li> <a href="#" aria-label="Previous"> <span aria-hidden="true"><?php previous_posts_link(); ?></span> </a> </li>
<li class="active"><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li>
<?php next_posts_link( ); ?>
<?php endif; ?>
ASKER
Hi Terry Woods thanks for the info . Let me try
Also, don't forget to include: 'posts_per_page=3'
3 being the number of posts per page you would like to see.
3 being the number of posts per page you would like to see.
ASKER
It seems not working . I tried with the
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$custom_query = new WP_Query('cat=6&posts_per_page=6&paged='.$paged);
$pagination = array(
'base' => '%_%',
'format' => '?page=%#%',
'total' => $the_query->max_num_pages,
'prev_next' => True,
'prev_text' => __( '<< Previous' ),
'next_text' => __( 'Next >>' )
);
echo paginate_links($pagination);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tried with your code . But Still am not getting the pagination for my Blog page
Open in new window
Documentation: https://codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query