Dunkkan
Member
Posted 3 years ago #
Hello guys,
I'm currently working in a custom loop :
<?php query_posts ($query_string.'&offset=3') ; ?>
<?php
if (have_posts()) :
while (have_posts()) :
the_post();
?>
<!-- etc -->
I need to add something to exclude certain category by its slug.
I don't know how to do it.
Many thanks for any help !
Dunkkan
Member
Posted 3 years ago #
This doesn't seems to work. I founded here :
<?php query_posts ($query_string.'offset=3') ; ?>
<?php
if (have_posts()) :
while (have_posts()) :
the_post();
?>
<?php if ( is_category('MySlugToExclude') ) continue; ?>
<!-- rest of the loop here -->
I tried both : in_category and is_category, but I'm printing still what I try to exclude.
Something like:
<?php
$slug = 'cat-slug-here';
$category = get_category_by_slug($slug);
query_posts($query_string . '&cat=' . $category->cat_ID);
?>
Dunkkan
Member
Posted 3 years ago #
Michael, this is actually awesome. I just added a negative sign in '$cat=-'.
Thank you !
winmonaye
Member
Posted 3 years ago #
Does anyone know how to exclude post from certain category even if post are belong to multiple category.
Example-> Post A belongs to Category B and C
i used query_post with cat=-B
And Post A still show (I guess) because it belongs to C.
Is there any work around??
Thank you,