我在带有类别行的父帖子类型存档页面上显示每个类别 4 个自定义帖子类型帖子。我想显示类别帖子的数量($list->found_posts),但我将显示的帖子限制为随机 4 个帖子。
<?php $list = new WP_Query (array(
'posts_per_page' => 4,
'post_type' => 'business_listing',
'category__in' => 5,
'orderby' => 'rand'
)) ;
我已成功显示每个类别的帖子总数(business_listing 是帖子类型)
$listCat = get_category('5');
$catName = get_field('display_name', $listCat);
$numberPosts = wp_count_posts($list);
echo '<h3 class="directory text-left">'. get_cat_name($category_id = '5') .' ('. $list->found_posts .' of '. $list->found_posts .') <a href="'. get_category_link($listCat) .'">View All</a></h3>';
问题是,我的一些查询少于 4 posts_per_page。所以我想计算最多 4 个,所以如果该值小于 4 个帖子,它只会计算该数字。例如,如果有 2 个帖子,则会显示 2 of 2。但如果有 30 个帖子,则会显示 4 of 30。
我希望这是有道理的。感谢您的帮助。
白衣染霜花
region数量分配问题
显示数量呀
关于局部变量和全局变量
j输出空格的数量