我有以下循环,它假设将所有分类法称为系列及其下的帖子。它工作正常,但问题是它不是没有显示较旧的帖子链接。我手动转到第二页更新的帖子链接显示。知道我错过了什么吗?
<?php
$page = ( get_query_var('paged') ) ? get_query_var( 'paged' ) : 1;
$per_page = 5;
$offset = ( $page-1 ) * $per_page;
$args = array( 'number' => $per_page, 'offset' => $offset, 'hide_empty' => 0,'paged' => $page);
$terms = get_terms('series',$args);
foreach ($terms as $term) {
$wpq = array ('taxonomy'=>'series','term'=>$term->slug);
$myquery = new WP_Query ($wpq);
$article_count = $myquery->post_count;
echo "<h3 class=\"term-heading\" id=\"".$term->slug."\">";
echo $term->name;
echo "</h3>";
if ($article_count) {
echo "<ul>";
while ($myquery->have_posts()) : $myquery->the_post();
echo "<li><a href=\"".get_permalink()."\">".$post->post_title."</a></li>";
endwhile;
echo "</ul>";
} } ?>
<div class="clear"></div>
<p class="previous"><?php next_posts_link( __( '← Older posts', 'ari' ) ); ?></p>
<p class="next"><?php previous_posts_link( __( 'Newer posts →', 'ari' ) ); ?></p>
</div>
答案 0 :(得分:0)
尝试这个(我已经测试过),分页不适合偏移,这对于get_terms()更好(但对get_query_var('paged')仍然有用),也将“类别”更改为您想要的术语。
<?php
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
$per_page = 4;
$offset = ( $page-1 ) * $per_page;
$args = array( 'number' => $per_page, 'offset' => $offset, 'hide_empty' => 0);
$terms = get_terms('category', $args);
foreach ($terms as $term){
$wpq = array ('taxonomy'=>'category','term'=>$term->slug);
$myquery = new WP_Query ($wpq);
$article_count = $myquery->post_count;
echo "<h3 class=\"term-heading\" id=\"".$term->slug."\">";
echo $term->name;
echo "</h3>";
if ($article_count){
echo "<ul>";
while ($myquery->have_posts()) : $myquery->the_post();
echo "<li><a href=\"".get_permalink()."\">".$post->post_title."</a></li>";
endwhile;
echo "</ul>";
}
} ?>