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 want to create a loop that excludes a category and only displays a certain number of posts per page.

I have tried both have_posts and query_posts to do this, but I'm a bit stuck on the most effective method. What would you use to do this?

share|improve this question
up vote 1 down vote accepted

Just use a custom query like this:

$exclude_cats = '2,52,3';
$posts_per_page = '4';
$loop = new WP_Query("category__not_in=$exclude_cats&posts_per_page=$posts_per_page");
if($loop->have_posts()):
    while($loop->have_posts()): $loop->the_post();
        //Do stuff here the_content(), the_title() etc...
    endwhile;
else:
    //Do something here
endif;
share|improve this answer

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.