537 posts
  • Author had a File in an Envato Bundle
  • Bought between 500 and 999 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Interviewed on the Envato Notes blog
  • Netherlands
  • Referred between 50 and 99 users
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+2 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?

2429 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Europe
  • Bought between 10 and 49 items
  • Referred between 100 and 199 users
  • Sold between 100 and 1 000 dollars
  • Microlancer Beta Tester
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
  • Author had a File in an Envato Bundle
  • Bought between 500 and 999 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Interviewed on the Envato Notes blog
  • Netherlands
  • Referred between 50 and 99 users
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+2 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
  • United States
  • Attended a Community Meetup
  • Author had a Free File of the Month
  • Bought between 50 and 99 items
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Has been a member for 5-6 years
  • Contributed a Tutorial to a Tuts+ Site
  • Contributed a Blog Post
+4 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

2317 posts
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Author had a Free File of the Month
  • Bought between 10 and 49 items
  • Europe
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 100 and 199 users
+1 more
CreativeMilk says
4266 posts ThemeForest Reviewer
  • Envato Staff
  • Reviewer
  • Community Moderator
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Venezuela
  • Has been a member for 5-6 years
  • Microlancer Beta Tester
  • Sold between 10 000 and 50 000 dollars
  • Exclusive Author
+9 more
Ivor Reviewer says

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

2429 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Europe
  • Bought between 10 and 49 items
  • Referred between 100 and 199 users
  • Sold between 100 and 1 000 dollars
  • Microlancer Beta Tester
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
  • United States
  • Attended a Community Meetup
  • Author had a Free File of the Month
  • Bought between 50 and 99 items
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Has been a member for 5-6 years
  • Contributed a Tutorial to a Tuts+ Site
  • Contributed a Blog Post
+4 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

2429 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Europe
  • Bought between 10 and 49 items
  • Referred between 100 and 199 users
  • Sold between 100 and 1 000 dollars
  • Microlancer Beta Tester
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