无法让pagnation在自定义帖子类型类别页面上工作。它在显示自定义存档页面时有效。当我点击pagnation时,它显示第一页的帖子,但URL显示page = 2。
这是我在archive-slug.php中使用的代码。如何自定义它以使用taxonomy-slug.php?
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
query_posts( array( 'post_type' => 'dropshippers', 'paged' => $paged ) );
$loop = new WP_Query( array( 'post_type' => 'dropshippers', 'paged' => get_query_var( 'paged' ), 'posts_per_page' => 8 ) );
if(have_posts()) : while(have_posts()) : the_post();
//Posts
endwhile; endif;
if(function_exists('wp_pagenavi')) {
wp_pagenavi( array( 'query' => $loop ) );
} else {
echo "No posts";
}
答案 0 :(得分:1)
您需要在查询中添加您的类别名称,我更喜欢使用get_posts:
<?php $args = array(
'posts_per_page' => 8,
'offset' => 0,
'category' => '',
'category_name' => '',
'orderby' => 'date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'dropshippers',
'post_mime_type' => '',
'post_parent' => '',
'author' => '',
'post_status' => 'publish',
'suppress_filters' => true
);
$posts_array = get_posts( $args ); ?>
用你的args填充这两行:
'category' => '',
'category_name' => '',