Excluding One Category From Blog Homepage (WordPress)

[fr]

Comment exclure une catégorie de la première page de votre blog WordPress tout en la gardant dans les archives.

[en]

The simplest method I’ve found up to now (and I’ve only just found it) if there are certain categories of posts you do not want to see appear on your main blog page, but that you still want to see in the archives, is to use query_posts().

Here’s an example:

<?php
if (is_home()) {
   query_posts($query_string . "&cat=-3");
}
?>

This needs to come in right before the while ( have_posts() ) { line. The $query_string parameter means that you can still pass parameters in the URL, so things like special Event Calendar pages will still work.

Careful, though, this only works for one category at a time. You need to use WP_Query for that, and build a separate loop for the homepage.

Viewing 4 Comments

Trackbacks

blog comments powered by Disqus
Contact