How To: Exclude Categories to be Posted on FrontPage
Posted in: WordPress
On this post I will show you how to hide a particular post on your blog’s front page without the need to install a plugin. I have nothing against WordPress plugins it’s just that I’m the type of WordPress blogger who is as much as possible doesn’t want to install a plugin especially if there’s a code that I can use and do it manually by editing my theme’s template. On today’s post I will show you on how to exclude categories to be posted on your frontpage of your WordPress blog. This WordPress tweak has been tested in WordPress 2.3. This definitely works especially if your frontpage has page navigation.
* This varies depending on your theme, this is commonly used in a normal wordpress blog layout.
- Go to admin dashoard > manage > categories. Look for the category you want to exclude and identify the category ID. e.g. we want to hide category ID: 8.
- Still in the admin dashboard > go to Presentation > Theme Editor > open *index.php
- Inside the *index.php file, look for the line that says “<?php if (have_posts()) : ?> ”
then paste this code after that line:
! don’t forget to change the id to your chosen category id<?php $page = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("cat=-8&paged=$page"); ?>and before this code. “ <?php while (have_posts()) : the_post(); ?> “
- Then Update your *index.php file.














































This is a good tips that I will try soon.
Thanks mate.
thanks ,works perfectly.
No problem. Glad I was able to help you out.
Can’t see all the code maybe in this browser?
The code to add is this?
! don’t forget to change the id to your chosen category id
<?php $page = (get_query_var(’paged’)) ? get_query_var(’paged’) :
where is the category type placed?
Thanks,
Todd
You are right Todd… It is also not working for me too. I am going to try in other browser.
jaaahhh… where i have to put the categoryid?? paged???
try this guys:
it works!… place this code as same as dona’s mentioned above
sorry, this the code, (i forgot to replace it as html code)
<?php
if (is_home()) {
query_posts("cat=-3");
}
?>
Not working for me… I am using version 2.6.1. Where to change the category id?
Thank you, it works on my 2.6.3
Here is another way to do it. You can use this code snippet in the index.php file instead: