Forums

Include and exclude multiple categories +children (4 posts)

  1. frmars
    Member
    Posted 1 year ago #

    Hello
    After a 2 hours search, I am just lost.

    My theme is quite a complex one, and complexity is growing. On my home, a first column already sorts various categories :

    <?php query_posts('cat=-6,-25,-50,-51&paged='.$paged); ?>

    I now need, IN THE SAME FORMULA, to exclude a specific category AND ALL ITS CHILDREN.

    This specific category and children are meant to create a kind of "sub-blog" and must not appear in the main flow of articles.

    Please, could you help ?

    ------------------------------------

    I've seen messages about this on the forum, but never so complex.

    (see http://wordpress.org/support/topic/exclude-posts-from-children-categories-with-query_postsget_posts?replies=4

    or

    http://wordpress.org/support/topic/how-to-exclude-child-category-content-from-parent-category-default-display

  2. frmars
    Member
    Posted 1 year ago #

    May I add that I created the category I want to exclude SPECIFICALLY, so that I could exclude (but how ?) straight away all its children from the homepage ?

  3. frmars
    Member
    Posted 1 year ago #

    Can anyone help me ?

  4. vtxyzzy
    Member
    Posted 1 year ago #

    This is UNTESTED, but it should be close:

    <?php $blog_cat = 22;  // The blog parent category ID
    $cat_excludes = array(6,25,50,51);
    $children = get_categories("child_of=$blog_cat");
    foreach ($children as $child) {
       $cat_excludes[] = $child->cat_ID;
    }
    $args = array(
       'paged' => $paged,
       'category__not_in' => $cat_excludes
    );
    query_posts($args); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic