ThemeShaper Forums » Thematic

[closed]

remove child_of category from Blog

(1 post)
  • Started 10 years ago by kgoodman
  • This topic is not resolved
  1. kgoodman
    Member

    Hi -
    First, I've been thru the Forum and successfully removed specific Categories from the Main Blog and even have the prev/next post navigation working accordingly.

    But, besides excluding two specific categories by ID, I also need to exclude the CHILDREN OF or DESCENDANT of a certain category. I'm having trouble concantentating the arguments.

    I think there should be an additional argument in this line of code:
    $query->set('cat', '-6,-23');
    where I would add the exclusion of the child of '23'

    In Codex found post_is_in_descendant_category which works great on its own in the prev/next filter
    if (in_category('6') || in_category('23') || post_is_in_descendant_category))
    but it breaks here
    'excluded_categories' => '6 and 23');
    since I can't figure out how to exclude these 2 specific categories AND the child of a category.

    I hope this makes sense. I just need help combining remove category IDs AND child of a category ID.

    Thanks for your help, as always. Love Thematic!
    Kyndra

    Here's the working code from my child theme functions.php

    //this EXCLUDES Categories 6 & 23 from Main BLOG
    function exclude_category($query) {
    if ( $query->is_feed || $query->is_home ) {
    $query->set('cat', '-6,-23');
    }
    return $query;
    }
    add_filter('pre_get_posts', 'exclude_category');

    //this handles the excluded categories from prev/next links.
    function childtheme_previous_post_link_args($args) {
    global $wp_query;
    $category = get_the_category();
    echo $category->cat_ID;
    if (in_category('6') || in_category('23')) {

    $args = array ('format' => '%link',
    'link' => '<span class="meta-nav">«</span> %title',
    'in_same_cat' => TRUE,
    'excluded_categories' => '');
    }
    else {
    $args = array ('format' => '%link',
    'link' => '<span class="meta-nav">«</span> %title',
    'in_same_cat' => FALSE,
    'excluded_categories' => '6 and 23');
    }
    return $args;
    }
    add_filter('thematic_previous_post_link_args', 'childtheme_previous_post_link_args');

    function childtheme_next_post_link_args($args) {
    global $wp_query;
    $category = get_the_category();
    echo $category->cat_ID;
    if (in_category('6') || in_category('23')) {
    $args = array ('format' => '%link',
    'link' => '%title <span class="meta-nav">»</span>',
    'in_same_cat' => TRUE,
    'excluded_categories' => '');
    }
    else {
    $args = array ('format' => '%link',
    'link' => '%title <span class="meta-nav">»</span>',
    'in_same_cat' => FALSE,
    'excluded_categories' => '6 and 23');
    }
    return $args;
    }
    add_filter('thematic_next_post_link_args', 'childtheme_next_post_link_args');

    Posted 10 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.