Community Forums › Forums › Archived Forums › Design Tips and Tricks › Hiding selected categories
Tagged: exclude category, homepage
- This topic has 6 replies, 2 voices, and was last updated 11 years, 7 months ago by
Dorian Speed.
-
AuthorPosts
-
July 5, 2013 at 1:31 pm #49384
middayminer
MemberHi, I want to create a couple of categories where I can publish posts on but not have them show up on the homepage, is there a way to set their visibility that way? Googling shows me a plugin for this but it doesn't look very compatible, plus it's not listed on wordpress.org.
Using the prose theme btw.
July 5, 2013 at 2:51 pm #49404Dorian Speed
MemberWhich is it that you want to do - exclude posts that are in a particular category from the homepage, or not have the label for that particular category name show up beneath posts that are on the homepage?
I am going to assume it's the former, in which case you should add the following code to your functions.php file. (Make sure you do this via FTP and make a backup copy of functions.php before you make any changes, because it's possible to encounter the White Screen of Death if you accidentally leave out a semicolon or other small errors when editing PHP.)
if ( is_home() ) {
query_posts( 'cat=-3' );
}That would work for the category with the ID of 3. To easily see the ID numbers for categories, posts, etc., you can install a plugin called Reveal IDs that will add a column with the ID numbers.
You can read more about how to implement this here on the codex.
Bringing websites Up to Speed
Firebug will light the way to understanding the secrets of the Internet!July 5, 2013 at 4:08 pm #49424middayminer
MemberHi Dorian, thanks for replying! 🙂
Well, I think I have to defer on the file I should be editing, because the codex entry says I have to put the code in index.php
Problem is, it still doesn't work. I assume the index.php it's referring to is the one directly in the wp-content folder? There's one or two in the theme folders and thereabouts. Either I break the website, or get no change. http://www.foundwonders.com
pretty much just using`
<?php if ( is_home() ) { query_posts( 'cat=-33' ); } ?>
To confirm, the category is indeed the one called 'pending approval', ID 33. I'm very likely just missing something obvious.
Oh, and I have seen more than a few white screens since I started making the website, but always have a backup of the file handy. Very thankful that nothing has irreversibly broken yet.
July 5, 2013 at 4:41 pm #49430Dorian Speed
MemberLet's see - so, did you try adding it to functions.php? Here's another solution via Bill Erickson, WordPress/Genesis Genius.
Bringing websites Up to Speed
Firebug will light the way to understanding the secrets of the Internet!July 5, 2013 at 4:43 pm #49431Dorian Speed
MemberCompletely unrelated: if you're using this to filter posts based on a workflow of some sort, I would recommend you check out the superfantastic plugin Edit Flow. It uses custom statuses and lots of other neat features to flag posts that still need approval/components before they're ready for prime time. Here's a nice overview that Suzette Franck did of the plugin and its various features.
Bringing websites Up to Speed
Firebug will light the way to understanding the secrets of the Internet!July 5, 2013 at 5:02 pm #49436middayminer
MemberI did try it there just in case, and in custom code at well. No luck.
This from the comments section of your link does work though!function exclude_cat($query) { if ( $query->is_home) { $query-> set('cat','-33'); } return $query; } add_filter('pre_get_posts','exclude_cat');
And indeed I am trying to sort out my workflow and other terrible things that get in the way of making content happen. Thanks for both the help and the tip! 🙂
July 5, 2013 at 9:53 pm #49474Dorian Speed
MemberExcellent! Glad you got it working the way you want. Feel free to hit me up for questions about Edit Flow if you do use it. You can mark this thread as resolved if your question was answered.
Bringing websites Up to Speed
Firebug will light the way to understanding the secrets of the Internet! -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.