Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm having a dozy of a time on this one and have finally had to break down and ask my first question. Usually I can find an answer on here, but this time I need some help. I'm trying to exclude a category from the main loop so that it does not show up twice on my index page. I have searched up and down and came across this code here:

 <?php
 $category_id = get_cat_ID('featured');
 $q = 'cat=' . $category_id;
 query_posts($q);
 if (have_posts()) : while (have_posts()) : the_post();

 the_content();

 endwhile; endif;?>

It worked, but then my page navigation didn't work. Even if you clicked on page 2 you still got page one content. Not sure why that happened. I don't want to exclude the category with the ID because the ID will change, but the name will always be the same.

Any help on this would be great, Thanks! If you need the demo site then just ask.

share|improve this question
add comment

1 Answer 1

You directly cannot pass the name or slug for excluding a particular category. You have to use the id. Modifying your code:

<?php
    $category_id = get_cat_ID('featured');
    //if get_query_var('paged') doesn't work, then try using get_query_var('page') in the next line.
    $paged = (get_query_var('paged'))?get_query_var('paged'):1;
    $q = array();
    $q['category__not_in'] = array($category_id);
    $q['paged'] = $paged;
    query_posts($q);
    if (have_posts()) : while (have_posts()) : the_post();

    the_content();

    endwhile;
    endif;
?>

Hope this helps!

share|improve this answer
    
I tired it, but I still get the same problem. It will exclude the 'featured' category from the main page, but the navigation will not work. I'm trying to exclude the featured category from the main area on the index page. Below is a link to my wordpress site with the above code in there. tgpwp.com/demoV2 –  Steve Oct 4 '11 at 19:33
    
You mean the pagination? I'm modifying the code, check it. –  Rutwick Gangurde Oct 5 '11 at 4:34
    
Yes, that one worked. Thank you so much for helping me with this! –  Steve Oct 7 '11 at 22:29
    
Awesome! You're welcome! Please mark the answer as correct! –  Rutwick Gangurde Oct 8 '11 at 3:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.