Reputation: 4323
For some reason, everything works on this WP_Query
apart from the pagination at the bottom, nothing is outputted from paginate_links()
.
I can't work out why, the query returns all correct items, and the page_per_posts
works fine, I can even visit the rest by directly visiting the urls /page/2/
etc.
Why isn't the pagination showing?
// Get only the posts with Press Release category
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$pressRelease_posts = new WP_Query(array(
'paged' => $paged,
'posts_per_page' => get_option('posts_per_page'),
'category_name' => 'press-releases'
));
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="module entry-content">
<?php the_content(); ?>
<?php if($pressRelease_posts->have_posts()) { ?>
<?php while($pressRelease_posts->have_posts()) { $pressRelease_posts->the_post(); ?>
// custom query looped item
<?php } ?>
<?php } ?>
<?php get_template_part('nav', 'below'); ?>
<?php wp_reset_postdata(); ?>
</div>
</article>
<?php endwhile; endif; ?>
On a separate note, whenever I try to add the tag WP_query
to this question, it doesn't show up when saving? Any reasons why?
The nav-below.php file contains:
<div class="bv-pagination marginbottom2 text-center">
<?php echo paginate_links(array(
'prev_text' => '<span class="fa fa-fw fa-chevron-left"></span>',
'next_text' => '<span class="fa fa-fw fa-chevron-right"></span>'
)); ?>
</div>
Upvotes: 0
Views: 443
Reputation: 9373
Implement this code in your file. It will be helpful.
<?php
$args = array(
'posts_per_page' => 5,
'post_type' => 'post' ,
'orderby' => 'date',
'order' => 'DESC',
'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1
);
$postslist = new WP_Query( $args );
?>
<div class="row section blog-posts">
<?php while ( $postslist->have_posts() ) : $postslist->the_post(); ?>
<div class="blog-post">
</div>
<?php endwhile; ?>
<div class="page-controls">
<?php echo paginate_links(
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' => ''
)
);
wp_reset_postdata();
?>
</div>
</div>
Upvotes: 1