exclude category
-
Can i Exclude one category from the front page? How to do it?
-
Hi Jurgiel,
Please replace following code in header.php file
$args = array();by
$args = array( 'exclude' => array(category_id ) );Here category_id refers to the id of the category that you want to exclude in front page. More than one category can be excluded by adding category id separated by a comma like category_id1, category_id2. For further details you can also refer to http://codex.ww.wp.xz.cn/Function_Reference/get_categories.
And also please find $categories = get_categories(); and delete it from header.php
Thank You
oh no! Thank You. Works perfectly 🙂
Bonjour!
I have excluded some categories like jurgiel did and this works nice.
But when “show all” is selected again, all categories are shown.
Where can I change this?
Thanks a lot.The Test Site:
http://www.wp.pep-berlin.de/wp/The code:
<ul class="nav-listing clearfix"> <li><a href="#" data-filter="*" class="selected"><span></span><?php _e('Show All','sampression'); ?></a></li> <?php /*to exclude some categories */ $args = array( 'exclude'=> array(8,9,10,11,12) ); $categories = get_categories($args); foreach($categories as $category): ?> <li><a href="javascript:void(0);" data-filter=".<?php echo $category->slug; ?>" id="<?php echo $category->slug; ?>" class="filter-data"><span></span><?php echo $category->name; ?></a></li> <?php endforeach; ?> </ul>that’s strange. But today i posted news on excluded category and it showed up in the main page. I checked and everything seams to be all right.
Hello jurgiel,
would you send me teh URL you are talking about?
Maybe it can help me.
Thank you.zabawy.zielonagrupa.pl
The excluded category is “Aktualnosci” but the first post – with the photo is from this category.
Thanks a lot
Hello
the other post from your category-1, “Ruszamy”, ist also schown on the home page. So it seems like your “exclude” does not work.
I think we don’t habe exacttlx the same problem: my “exclude” works by loading of the home-page but not any more when you choose “show all” once more.Have you wrote
$args = array( 'exclude' => array(1) );?
hmmm thats true. The category isn’t shown, but the post are.
You see – the ‘Aktualnosci’ category is excluded in the menu – but the post are visible.Anybody know how to change it?
EDIT: yes i wroted
$args = array( 'exclude' => array(1 )Her is how “my” script for the entire list would look like in your case:
<ul class="nav-listing clearfix"> <li><a href="#" data-filter="*" class="selected"><span></span><?php _e('Show All','sampression'); ?></a></li> <?php $args = array( 'exclude'=> array(1) ); $categories = get_categories($args); foreach($categories as $category): ?> <li><a href="javascript:void(0);" data-filter=".<?php echo $category->slug; ?>" id="<?php echo $category->slug; ?>" class="filter-data"><span></span><?php echo $category->name; ?></a></li> <?php endforeach; ?> </ul>Thats exacly what i have. And still, the category is excluded, but it posts are one the main page
Well, I hope the author can soon help us…
The above code removes the category from the filter menu only, if you do not want the post from the particular category on the posts as well you have to add ‘category__not_in’ => array(category_ids) argument in the query that is in the index.php file.
Please find
query_posts( array( 'post__not_in' => get_option( 'sticky_posts' ), 'paged' => $paged ) );in the index.php file and replace it by
query_posts( array( 'post__not_in' => get_option( 'sticky_posts' ), 'category__not_in' => array(category ids separated by comma), 'paged' => $paged ) );Hope this is what you are looking for.
Thanks a lot.
The topic ‘exclude category’ is closed to new replies.
