【发布时间】:2012-11-15 11:09:13
【问题描述】:
我在为单个帖子添加下一个和上一个链接时遇到问题(我不想要下一个帖子,我需要下一组帖子)。
该网站的工作方式是,当前帖子显示在页面顶部,所有相关帖子的列表显示在下方,并带有分页。显示相关帖子的查询是:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'category__in' => $search_categories,
'posts_per_page' => 4,
'paged' => $paged
);
$search_term = null;
if ( isset( $_GET['search_term'] ) ) {
$args['s'] = esc_attr( $_GET['search_term'] );
}
$twp_query = new WP_Query( $args );
我知道查询返回了足够多的帖子。
这是循环(去除所有标记)
if ( $twp_query->have_posts() ) {
while ( $twp_query->have_posts() ) {
$twp_query->the_post();
get_template_part( 'post', 'listitem' );
}
next_posts_link('Next', $twp_query->max_num_pages);
previous_posts_link('Previous ', $twp_query->max_num_pages);
} else {
_e( 'Apologies, but no results were found.', 'rep' );
}
它显示返回的前 4 个项目,但不显示下一个和上一个帖子链接。
我会很感激任何帮助,因为这个让我很难过!
更新:
刚刚尝试将 'nopaging' => false 添加到 args 数组,没有运气。
另一个更新:
查看了wp-includes/link-template.php中get_next_posts_link的WordPress,从这段代码来看,这是不可能的。除非其他人知道不同?
if ( !is_single() && ( $nextpage <= $max_page ) ) {
$attr = apply_filters( 'next_posts_link_attributes', '' );
return '<a href="' . next_posts( $max_page, false ) . "\" $attr>" . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $label) . '</a>';
}
【问题讨论】: