[wp-trac] [WordPress Trac] #17069: missing get_term_parents() function
WordPress Trac
wp-trac at lists.automattic.com
Wed Apr 6 23:58:20 UTC 2011
#17069: missing get_term_parents() function
-------------------------+-------------------------------------
Reporter: thomask | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version: 3.1
Severity: normal | Keywords: needs-testing has-patch
-------------------------+-------------------------------------
we got get_category_parents
(http://core.trac.wordpress.org/browser/tags/3.1/wp-includes/category-
template.php#L30)
which use $parent = &get_category( $id ); limited to 'category' taxonomy,
but there is nothing similar to other taxonomies. IMO we should rewrite
this function to be generic and use it as get_term_parents function, the
existing get_category_parents would use that get_term_parents, so
something like (sorry, i do not know how to use diff) this:
{{{
42 function get_term_parents( $id, $taxonomy, $link = false,
$separator = '/', $nicename = false, $visited = array() ) {
43 $chain = '';
44 $parent = &get_term( $id, $taxonomy );
45 if ( is_wp_error( $parent ) )
46 return $parent;
47
48 if ( $nicename )
49 $name = $parent->slug;
50 else
51 $name = $parent->name;
52
53 if ( $parent->parent && ( $parent->parent !=
$parent->term_id ) && !in_array( $parent->parent, $visited ) ) {
54 $visited[] = $parent->parent;
55 $chain .= get_term_parents( $parent->parent,
$link, $separator, $nicename, $visited );
56 }
57
58 if ( $link )
59 $chain .= '<a href="' . get_term_link(
$parent->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts
in %s" ), $parent->name ) ) . '">'.$name.'</a>' . $separator;
60 else
61 $chain .= $name.$separator;
62 return $chain;
63 }
}}}
and
{{{
function get_category_parents( $id, $link = false, $separator = '/',
$nicename = false, $visited = array() ) {
return get_term_parents ($id,'category',$separator,$nicename,$visited);
}
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/17069>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list