我正在使用一个快捷码来显示自定义查询。短代码在页中使用。一切都很好,只是导航我不能让它正常工作。
下面是我用来显示通过快捷码调用的查询的函数:
$the_query = my_custom_query();
if($the_query){
if ($the_query->have_posts()) :
while ($the_query->have_posts()) : $the_query->the_post();
echo \'<a href="\'.get_permalink().\'">\'.get_the_title().\'</a><br>\';
endwhile;
next_posts_link(); previous_posts_link(); //here I can\'t get it right.
else : $return_string = \'no result\';
endif;
}else{ echo \'ordinary page\';}
The
previous_posts_link()
和
next_posts_link()
没有出现。是因为短代码在页面主循环中吗?
Update这是用于获取自定义查询的函数
function my_custom_query(){
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args = array(
\'post_type\'=>any,
\'posts_per_page\'=> 1,
\'max_num_pages\'=> 10,
\'paged\'=>$paged,
\'meta_query\' => array(\'relation\'=>\'OR\',array(
\'taxonomy\' => \'tax1\',
\'field\' => \'slug\',
\'terms\' => \'tax1term\'
)),
\'tax_query\' => array(\'relation\'=>\'OR\',array(
\'key\' => \'metakey\',
\'value\' => array(5,30),
\'compare\' => \'compare\'
))
);
$custom_query = new WP_Query( $args);
return $custom_query;
}
UPDATE 2现在我可以得到
next_posts_link(); previous_posts_link();
显示。但问题是,它链接到了错误的页面。查询结果在每个页面上保持不变(无论是下一页还是上一页)。
$the_query = my_custom_query();
if($the_query){
if ($the_query->have_posts()) :
while ($the_query->have_posts()) : $the_query->the_post();
echo \'<a href="\'.get_permalink().\'">\'.get_the_title().\'</a><br>\';
endwhile;
previous_posts_link(\'Previous\',$the_query->max_num_pages); next_posts_link(\'Next\',$the_query->max_num_pages); //here I added $the_query->max_num_pages,and they shows up.
else : $return_string = \'no result\';
endif;
}else{ echo \'ordinary page\';}