我的wordpress网站上有一个静态的首页,我正在努力让分页工作。
如果我手动转到地址(/ 2 /,/ 3 / etc)但是next_posts_link和previous_posts_links根本不起作用,那么分页实际上有效。
有人可以找出我的错误吗?
<?php $args = array(
'posts_per_page' => 10,
'ignore_sticky_posts'=> 1,
'category__in'=> $cat,
'paged' => $paged,
);
$featured_query = new WP_Query($args);
while ($featured_query->have_posts()) : $featured_query->the_post();
?>
<?php get_template_part( 'template-parts/content', get_post_format() ); ?>
<?php endwhile;?>
<?php wp_reset_postdata(); ?>
<div class="nav-previous alignleft"><?php next_posts_link( 'Older posts', $featured_query->max_num_pages ); ?></div>
<?php if(is_paged()) { ?>
<div class="nav-next alignright"><?php previous_posts_link( 'Newer posts', $featured_query->max_num_pages ); } ?></div>
答案 0 :(得分:0)
您应该检查您的脚本,它可能和您无法访问的实际脚本文件,检查该特定元素。
答案 1 :(得分:0)
请尝试以下代码
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args_blog = array(
'post_type' => 'post',
'paged' => $paged,
'posts_per_page' => get_option('posts_per_page ')
);
$query_blog = new WP_Query( $args_blog );
if($query_blog->have_posts()) : while($query_blog->have_posts()) : $query_blog->the_post();
?>
<div class="pagination">
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'prev_text' => __('Prev'),
'next_text' => __('Next'),
'total' => $query_blog->max_num_pages
) );
?>
</div>
<?php
else :
get_template_part( 'content', 'none' );
endif;
?>
答案 2 :(得分:0)
试试这段代码:
您应该在发布链接后查看<?php wp_reset_postdata(); ?>
,请参阅更新的代码:
<?php
$args = array(
'posts_per_page' => 10,
'ignore_sticky_posts'=> 1,
'category__in'=> $cat,
'paged' => $paged,
);
$featured_query = new WP_Query($args);
while ($featured_query->have_posts()) : $featured_query->the_post();
?>
<?php get_template_part( 'template-parts/content', get_post_format() ); ?>
<?php endwhile;?>
<div class="nav-previous alignleft"><?php next_posts_link( 'Older posts', $featured_query->max_num_pages ); ?></div>
<?php if(is_paged()) { ?>
<div class="nav-next alignright"><?php previous_posts_link( 'Newer posts', $featured_query->max_num_pages ); } ?></div>
<?php wp_reset_postdata(); ?>