WordPress.org

Forums

How can i exclude the subcats of subcat of cat from here: (2 posts)

  1. arba
    Member
    Posted 5 years ago #

    <?php
     if ( is_category() ) {
    
    	$this_cat = get_category($cat);
    	$sub_cats = get_categories('child_of='.$this_cat->term_id.'&hide_empty=true&exclude=');
    
    	if ( !empty( $sub_cats ) ) {
    
    		foreach( $sub_cats as $sub ){
    
    			$link = get_category_link( $sub->term_id );
    			$link_title = $sub->name;
    
    			echo '<div class="post">';
    			echo '<h2><a href="'.$link.'" rel="bookmark" title="'.$link_title.'">'.$link_title.'</a></h2>';
    			echo $sub->description;
    			echo '</div>';
    		}
    	}
    }
    ?>
  2. arba
    Member
    Posted 5 years ago #

    Solved it already in this way:

    <?php
     if ( is_category() ) {
    
    	$this_cat = get_category($cat);
            $sub_cats = get_categories('child_of='.$this_cat->term_id.'&hide_empty=false&orderby=name');
    
    	if ( !empty( $sub_cats ) ) {
    		foreach( $sub_cats as $sub ){			
    
            if ( $sub->category_parent == $this_cat->term_id) {
    
    			$link = get_category_link( $sub->term_id );
    			$link_title = $sub->name;
    
    			echo '<div class="post">';
    			echo '<h2><a href="'.$link.'" rel="bookmark" title="Permanent Link to '.$link_title.'">'.$link_title.'</a></h2>';
    
    			echo $sub->description;
    			echo '</div>';
                            }
    		}
    	}
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic