开发者

Conditional use of wp_list_categories (Wordpress)

I am using the wp_list_categories tag in Wordpress. I would like to wrap this in a condition so it is only used when there are posts in the database. Something like:

if ($number_of_posts > "0") {
}

But I can't find a function that'll let me count the number of posts. Anyone know the soluti开发者_运维问答on?


i would use the loop idea with query posts

something like

query_posts('posts_per_page=1');
if(have_posts()) {
   // run code here!
}

Hope this helps :)


Found this snippet:

$num_pages = wp_count_posts( 'page' );     
$num_pages = $num_pages->publish; //publish

Which when used as follows, solves my problem:

<?php 
if ($num_posts > "0") {
wp_list_categories('title_li=Blog:'); 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜