views:

30

answers:

2

Hello

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 solution?

+1  A: 

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 :)

Rob
Found an answer already - but thanks!
YsoL8
No worries, just a suggestion but perhaps you could post your solution on here so others can learn from you?
Rob
A: 

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:'); 
}
YsoL8