我的自定义帖子类型循环分页工作正常。但是,我得到的网址就像:
"my-site.com/courses/page/3/"
但我想要得到的是:
"my-site.com/courses/page/3/?pag=3"
因此用户可以设置'?pag = 2'并重定向到" my-site.com/courses/page/2/?pag = 2"。 我已在索引页面中使用'?paged = 2'查询,但尚未在此。
我的代码:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
//$paged = (get_query_var('page')) ? get_query_var('page') : 1; IN INDEX PAGE
$args = array(
'post_type' =>'courses',
'posts_per_page' => 6,
'paged' => $paged,
'orderby' => 'title',
'order' => 'ASC'
);
$courses = new Wp_Query($args);
if($courses -> have_posts()):
while($courses -> have_posts()): $courses -> the_post();?>
<!-- HTML loop -->
<?php endwhile; ?>
<div class="pagination">
<?php
echo paginate_links(array( 'total' => $courses->max_num_pages,
'base' => add_query_arg('paged','%#%'),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged'))
//'current' => max(1, get_query_var('page')) IN INDEX PAGE
));
?>
</div>
<?php
endif;
wp_reset_postdata();
?>
谢谢!
答案 0 :(得分:1)
我使用了此代码,希望这可以帮助您进行细微更改。
global $wp_query,
$wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
$pagination = array(
'base' => @add_query_arg('page','%#%'),
'format' => '',
'total' => $wp_query->max_num_pages,
'current' => $current,
'show_all' => true,
'type' => 'list',
'next_text' => '»',
'prev_text' => '«'
);