Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

How to create custom blog template that excludes one category WordPress

  • SOLVED

Ah, I have forgotten everything.

[[LINK href="http://www.wpquestions.com/question/show/id/1737"]]I previously asked how to get a list of all the posts in the category of "collections"[[/LINK]]. Now I need to be reminded how do I create a page that holds a blog that lists all blog posts except for those posts that belong to the category of "collections".

I copied the index.php page and renamed the template to "blog". So now I have this "blog" template in a file I'm calling blog.php. But how can I modify the loop so it excludes any post that is in the category of "collections"?

Answers (1)

2011-02-26

Andrzej answers:

query_posts('cat=-X'); // X is cat_id you want to get rid of.
if (have_posts()) :
while (have_posts()) : the_post();
// post content here
endwhile;
else :
echo '<h3>Oops, something went wrong.</h3>';
endif;
wp_reset_query();


where, in "query_posts", X is collections category ID


Lawrence Krubner comments:

Look here:

[[LINK href="http://dev16.teamlalala.com/?page_id=7"]]http://dev16.teamlalala.com/?page_id=7[[/LINK]]

I get nothing but the "hi"s. And yet there is one post that is not in this category



get_header(); ?>

hi
<div id="container">
<div id="content" role="main">

<?php
/* Run the loop to output the posts.
* If you want to overload this in a child theme then include a file
* called loop-index.php and that will be used instead.
*/
// get_template_part( 'loop', 'index' );


query_posts('cat=-3'); // X is cat_id you want to get rid of.

if (have_posts()) :

while (have_posts()) : the_post();

// post content here

endwhile;

else :

echo '<h3>Oops, something went wrong.</h3>';

endif;

wp_reset_query();

?>

hi