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.

I have the following code, Assume this code spits back one post. the page displaying that post will also display pagination. Why? It shouldn't. This code only queries for posts that belong to the post type of post.

    protected function _general_wordpress_loop(){
        query_posts("post_type=post");
        if($this->_wp_query->have_posts()){
            while($this->_wp_query->have_posts()){
                $this->_wp_query->the_post();

                if(isset($this->_options['post_before'])){
                    echo $this->_options['post_before'];
                }   

                $this->_components->thumbnail($this->_options);

                $this->_components->title($this->_options);

                the_excerpt();

                if(isset($this->_options['post_after'])){
                    echo $this->_options['post_after'];
                }
            }

            if(isset($this->_options['navigation_wrap'])){
                $this->_components->loop_navigation($this->_options['navigation_wrap']);
            }else{
                $this->_components->loop_navigation();
            }

        }else{
            $this->_components->error_page($this->_options);
        }
    }

A quick run down, we query the post type of post, state if we have more posts, while we have more posts display the post, after the while, display the pagination (if there is a wrap (divs) wrap the nav, else display as normal). If there are no posts, display a custom error page.

Pretty basic and simple stuff. How ever I am getting pagination for things like, the category test has one post and I can see pagination.

is there a way to say "if you have more then one post display this?" I know if(have_posts()){} will do what ever assuming it has more then 0 posts which means pagination will be displayed by that logic.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

post_count property of query object will hold amount of posts queried.

Note that this is not often used and it is more common to display such elements by conditional logic (is_singular(), is_archive(), etc) or on template level.

PS query_posts() is evil and should not be used

share|improve this answer
    
Need better explanation on why not to use query posts. –  TheWebs Jun 18 '13 at 18:15
    
@TheWebs here you go :) wordpress.stackexchange.com/a/1755/847 –  Rarst Jun 18 '13 at 18:16

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.