WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been using Query Post for a newsticker which I have created so that the user navigate through the number of news by simply pressing Next & Previous buttons. But in case if there is only 1 news (i.e, only 1 post returned then there is no point of having Prev and Next button).

I will simply assign css attribute Display: none to the prev and next button if there is only 1 post. But how to find out if the query post returned just 1 post.

while (have_posts()): the_post();
share|improve this question
I strongly recommend you look at: slideshare.net/andrewnacin/… – Tom J Nowell Aug 7 '12 at 10:12

You should not use query_post when you can use the mutch faster query WP_Query.

You can count the post with the property post_count.

Here is a snippet that counts your post in the loop:


$args = array(
    'post_type'     =>  'post',
    'cat'           =>  '20',
    'post_status'   =>  'publish',
    'order'         =>  'DESC'


// The Query
$the_query = new WP_Query( $args );

// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();

    if( ( $the_query->post_count <= 1 ) {
        echo 'One or less';

    } else {

        echo 'More than one post';


// Reset Post Data

share|improve this answer
Something to read. – kaiser Aug 7 '12 at 13:17

Your Answer


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.