• Resolved scorpal

    (@scorpal)


    Hi.

    I have <?php echo(get_category_parents($cat, TRUE, ‘ ? ‘)); ?>

    The output is:

    Category With ID=10 ? Category With ID=22 ? Category With ID=28 ? Category With ID=14 ?

    How to trim output to some level?

    I need function that output will be:

    Category With ID=28 ? Category With ID=14 ?

    How to trim some categories from get_category_parents() but leave it childrens?

Viewing 1 replies (of 1 total)
  • Thread Starter scorpal

    (@scorpal)

    Think it was resolved by myself…

    function my_get_category_parents($id, $separator = '/', $visited = array()){
    	$chain = '';
    	$parent = &get_category($id);
    	if ( is_wp_error( $parent ) )
    		return $parent;
    
    		$name = $parent->cat_name;
    
    	if ( $parent->parent && ($parent->parent != $parent->term_id) && !in_array($parent->parent, $visited) && ($parent->parent != 49) ) {
    		$visited[] = $parent->parent;
    		$chain .= my_get_category_parents($parent->parent, $separator, $visited);
    	}
    
    		$chain .= '<a href="' . get_category_link($parent->term_id) . '" title="' . sprintf(__("View all posts in %s"), $parent->cat_name) . '">'.$name.'</a>' . $separator;
    	return $chain;
    }

    call with:

    <?php echo(my_get_category_parents($cat, ' ? ')); ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Trim list of parents categories’ is closed to new replies.