0

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.

1 Answer 1

0

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

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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