这就是我想做的:
如果帖子数量大于20->显示指向其他页面的链接(显示所有帖子)如果帖子数量小于20->不显示链接
到目前为止,我已经能够使用
$count_posts = wp_count_posts(\'inventory\');
$published_posts = $count_posts->publish;
但我不知道该怎么办,有什么建议吗?这就是我想做的:
如果帖子数量大于20->显示指向其他页面的链接(显示所有帖子)如果帖子数量小于20->不显示链接
到目前为止,我已经能够使用
$count_posts = wp_count_posts(\'inventory\');
$published_posts = $count_posts->publish;
但我不知道该怎么办,有什么建议吗?若我记得分类中正确数量的帖子被持久存储在category对象中。So使用get_category()
或它的变体,并从对象中提取数字。
示例代码(未测试):
$category = get_category($id);
$count = $category->category_count;
if( $count > $something ) {
// stuff
}
您可以从对象本身访问它:
foreach ( get_the_terms( get_the_ID(), \'taxonomy\' ) as $term )
{
printf( \'%s (%s)\', $term->name, $term->count );
}
另一种简单的方法是使用get_terms. 当我需要显示一个类别列表,并且需要忽略一个具有设置的最少帖子数量的类别时,我会使用这个选项。
$cats = get_terms(\'category\');
foreach($cats as $cat){
if($cat->count > 15){
//do something here eg. display category name
//echo \'catname : \' .$cat->name;
}
}
这难道不应该删除帖子吗?即使我删除了编辑器的delete\\u posts功能,他仍然可以丢弃帖子,然后永久删除I。那不可能是对的。如何删除垃圾/删除帖子的功能?