WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 20 months ago

Last modified 19 months ago

#4948 closed enhancement (worksforme)

Category Parent/Child Tree

Reported by: iacas Owned by:
Milestone: Priority: low
Severity: minor Version: 2.2.3
Component: Taxonomy Keywords:
Focuses: Cc:

Description

Short of building my own recursive function, I'd like WordPress to support a method to get a parent/child category ID tree. One function (get_category_parents) already does this except with the names of the categories. Another function, cat_is_ancestor_of in category.php appears to be usable, but I've been unable to get it to work.

In short, I'm trying to solve the problem of figuring out what top-most parent category a blog entry belongs to so that I can do some various things with CSS, sidebars, etc.

http://nslog.com/2007/09/09/wordpress_category_parents

Change History (8)

comment:1 ffemtcj6 years ago

  • Milestone changed from 2.5 to 2.7

No Patch. Moved to 2.7

comment:2 ryan6 years ago

  • Milestone changed from 2.7 to 2.8

comment:3 ryan5 years ago

  • Milestone changed from 2.8 to Future Release

comment:4 Denis-de-Bernardy5 years ago

  • Component changed from General to Template

comment:5 Denis-de-Bernardy5 years ago

  • Keywords needs-patch added

comment:6 Denis-de-Bernardy5 years ago

  • Component changed from Template to Taxonomy
  • Priority changed from normal to low
  • Severity changed from normal to minor

isn't this what child_of does in get_terms() et al?

comment:7 wonderboymusic20 months ago

  • Keywords needs-patch removed
  • Resolution set to worksforme
  • Status changed from new to closed

Use this:

$tree = get_terms( 'category', array( 
   'get'      => 'all', 
   'orderby'  => 'id', 
   'fields'   => 'id=>parent' 
) );

You can pass 'slug' => 'my-slug' for context

comment:8 helenyhou19 months ago

  • Milestone Future Release deleted
Note: See TracTickets for help on using tickets.