537 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Interviewed on an Envato blog
+7 more
Hein says

Hey guys,

What’s the fastest and easiest way to exclude category’s form the index.php.

I’ve added this in to my functions.php file but no luck.

if (is_home()) { query_posts("cat=-52,-1,-48,52"); }

And i tried this inside the index.php, it worked but when i ad more cat id’s it fails again.

<?php if (in_category('51')) continue; ?>

Anybody got any fresh ideas?

2450 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has referred 100+ members
  • Has been a beta tester for an Envato feature
+3 more
digitalimpact says

Try this:

<?php query_posts($query_string.'&cat=-1,-2,-3'); while (have_posts()) : the_post(); ?>

You should put it in your index.php file, not in the functions.php

Also, this should help:

http://codex.wordpress.org/Template_Tags/query_posts

537 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Interviewed on an Envato blog
+7 more
Hein says
Try this: <?php query_posts($query_string.'&cat=-1,-2,-3'); while (have_posts()) : the_post(); ?> You should put it in your index.php file, not in the functions.php

Perfect, that worked like a charm ;) thanks Di

2541 posts
  • Has referred 10+ members
  • Has sold $100+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Located in United States
+9 more
CreatingDrew says

I’m assuming you have a normal WordPress loop in index.php. If so try before your if conditional:


&lt;?php query_posts('cat=-52,-1,-48,52') ; if (have_posts()) : while (have_posts()) : the_post(); ?&gt;

I prefer custom loops with WP_Query object. Quick and easy loop:


<?php //pull out recent blog posts
$recent_posts = new WP_Query();
$recent_posts?>query('showposts=5&cat=-52,-1,-48,52');
while($recent_posts->have_posts()) :
$recent_posts->the_post();
?>
                <!--loop content here-->

<?php endwhile;?>

Hope that helps, WP rocks ;)

Edit – lol, looks like Digital Impact beat me to it :P

2324 posts
  • Has referred 100+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Helped several times protecting Envato Market against copyright violations
+6 more
CreativeMilk says
4336 posts ThemeForest Reviewer
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Member of the Envato Team
+12 more
Ivor Envato team says

Damn I love this forums, this worked for me too!!! Awesome! Thanks. :)

2450 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has referred 100+ members
  • Has been a beta tester for an Envato feature
+3 more
digitalimpact says
Perfect, that worked like a charm ;) thanks Di

Glad to be of help :)

EDIT : Drew, I had a WP theme open for editing, and I use the exact same code to remove categories. Otherwise it would have taken me longer :D

2541 posts
  • Has referred 10+ members
  • Has sold $100+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Located in United States
+9 more
CreatingDrew says
Perfect, that worked like a charm ;) thanks Di

Glad to be of help :)

EDIT : Drew, I had a WP theme open for editing, and I use the exact same code to remove categories. Otherwise it would have taken me longer :D

lol, I had a recent theme open too that I was copying and pasting from! :D

2450 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has referred 100+ members
  • Has been a beta tester for an Envato feature
+3 more
digitalimpact says
lol, I had a recent theme open too that I was copying and pasting from! :D

LOL Drew, did I just beat you at copy/pasting? :D:D:D

by
by
by
by
by
by