0

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?

1 Answer 1

1

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;

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.