【发布时间】:2015-02-04 12:47:17
【问题描述】:
我创建广告自定义帖子类型register_post_type( 'videos', $args);
以及register_taxonomy( 'video_category_categorie', 'videos', $args ); 的自定义分类法
每页最多显示 2 个帖子。通过 word press 后端
在存档视频中。 php 我写了用于显示来自特定分类的帖子(分类项 id 为 3)$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'post_type' => 'videos','paged' => $paged,'tax_query' => array(
array(
'taxonomy' => 'video_category_categorie',
'field' => 'term_id',
'terms' => 3)
));
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo get_the_title().'<br>';
endwhile;
twentyfourteen_paging_nav();
现在我正确地得到了结果,只显示了来自分类 id 3 的 pst。 但是分页不正确。它显示 1 2 3 4 。实际上有 5 个帖子在分类 id 3 中。所以正确的分页是 1 2 3 。
而且当点击 4 页面时,该页面没有显示任何帖子名称。
请帮忙
【问题讨论】:
-
如果你想要每页只有 2 个帖子,你需要告诉 WP_Query。添加:"posts_per_page" => 2 到您的 $args 数组中。
标签: wordpress wordpress-theming