出于某种原因,除了底部的分页之外,一切都在WP_Query
上有效,paginate_links()
没有输出任何内容。
我无法理解为什么,查询返回所有正确的项目,page_per_posts
工作正常,我甚至可以通过直接访问网址/page/2/
等访问其余项目。
为什么不显示分页?
// 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; ?>
另请注意,每当我尝试将标记WP_query
添加到此问题时,保存时都不会显示?有什么原因吗?
nav-below.php文件包含:
<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>
答案 0 :(得分:0)
在您的文件中实施此代码。这将有所帮助。
<?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>