Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

So hard to find this info...

I'd like to know a way to find out if there are pages. Something like:

if (has_pages()) { /* do something */ }

I can't find a reference to any similar function... how might one go about finding out if there are pages. In case yr wondering I'd like to only show a pages menu if there are pages.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

You could also use wp_list_pages() (Codex ref):

<?php
$has_pages = wp_list_pages( array( 'echo' => false ) );

if ( $has_pages ) {
    // There are pages; do something
}
?>
share|improve this answer
add comment

You might try using wp_count_posts, which will return an object with post statuses as properties. For example:

$count_pages = wp_count_posts( 'page' );
if ( $count_pages->publish > 0) {
   /* do something */
}

If you want to count all of the various statuses together, I imagine you'd just have to do a little addition before doing the compare.

share|improve this answer
    
That's some great lateral thinking there. Does it seem strange to you there is not a function already handling this scenario? –  Niels Jul 18 '11 at 15:49
    
I personally think wp_count_posts is pretty much right on, though maybe it would be nice if it came with an "all" property :) –  helenhousandi Jul 18 '11 at 18:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.