WordPress.org

Make WordPress Core

Opened 9 years ago

Closed 7 years ago

#2461 closed enhancement (fixed)

Add ability to limit depth of tree produced by wp_list_categories()

Reported by: researcher Owned by: pishmishy
Milestone: 2.5 Priority: normal
Severity: normal Version: 2.0.1
Component: Template Keywords: wp_list_categories has-patch
Focuses: Cc:

Description

the catstructure in WP is well known i think:

Parent1
 - Child1A
 - Child1B
Parent2
 - Child2A
 - - Child2A1
 - - CHild2A2

and so on.
if Parent2 is chosen with list_cats() you get also all the Children2XX. there is no logic in this from users perspective (if i call Matt, i don't wont to speak to his 12 children! sorry Matt).

my suggestion is; create 3 entities.

first entity = ThisCat     (the current category and show all posts)
second      = ParentCat  (should be turned ON or OFF, shows posts in the ParentCat YES or NO)
third         = ChildCat    (should be turned ON or OFF, shows posts in the ChildCat YES or NO)

Attachments (2)

2461.patch (698 bytes) - added by pishmishy 7 years ago.
Allows depth of tree walk to be set
2461-2.patch (709 bytes) - added by pishmishy 7 years ago.
Patch for wp_dropdown_categories()

Download all attachments as: .zip

Change History (15)

comment:1 @matt8 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Sorry, I don't understand this.

comment:2 @murky8 years ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

I'm not sure about the suggested solution, but I share the problem...

Essentially, WP category listing can be very bloated for the end user.

Parent1

  • Child1A
  • Child1B

Parent2

  • Child2A
  • - Child2A1
  • - CHild2A2

If viewing Parent2, it should be possible to make the ONLY child to be visible should be Child2A (or 2B etc)

I would like options to
1) show all parent categories (relevant if in a subcategory page)
2) show the parents of the current category (in the correct places, see below)
3) Show first children of current category
4) show sibling categories
5) An optional user controllable string could be tagged on if there were undisplayed children categories (default would be [+] )
6) The current category would be displayed with no link on it (allowing for css selection)

So with this structure:

Parent1

  • Child1A
  • - Child 1A1
  • - Child 1A2
  • - - Child 1A2A
  • Child1B

Parent2

  • Child2A
  • - Child2A1
  • - - Child2A1A
  • - CHild2A2
  • - - Child2A2A

Parent3

  • Child3A
  • - Child3A1
  • - CHild3A2

Suppose we looked at CHild2A2, it should be possible to display:

Parent1[+]
Parent2

  • Child2A
  • - Child2A1[+]
  • - CHild2A2
  • - - Child2A2A <--- no link for this cat

Parent3[+]

Much neater.... and easier to navigate.

comment:3 @murky8 years ago

Oops, for some reason Parent 1 and 2 got put on the same line... apologies.

comment:4 @foolswisdom8 years ago

  • Milestone changed from 2.1 to 2.4 (future)

comment:5 @pishmishy7 years ago

  • Summary changed from Categories and Posts, Parents and Children not separated in list_cats() to Add ability to limit depth of tree produced by list_cats()
  • Type changed from defect to enhancement

Reading over the ticket I believe this to be a more accurate description.

comment:6 @pishmishy7 years ago

  • Summary changed from Add ability to limit depth of tree produced by list_cats() to Add ability to limit depth of tree produced by wp_list_categories()

Oh and list_cats() is depreciated so...

@pishmishy7 years ago

Allows depth of tree walk to be set

comment:7 @pishmishy7 years ago

  • Keywords wp_list_categories has-patch added; list_cats removed
  • Owner changed from anonymous to pishmishy
  • Status changed from reopened to new

Trivial patch allows depth of tree walk to be set manually by the theme author. Defaults to existing value of 0. Documentation will need updating if it is decided to commit this patch.

Does a similar option need to be included for other tree walks?

comment:8 @pishmishy7 years ago

  • Status changed from new to assigned

comment:9 @palamedes7 years ago

This might have been addressed here;

http://trac.wordpress.org/ticket/5004

comment:10 @ryan7 years ago

(In [6595]) Add depth arg to wp_list_categories(). Props pishmishy. see #2461

comment:11 @ryan7 years ago

wp_dropdown_categories() could use the same thing.

@pishmishy7 years ago

Patch for wp_dropdown_categories()

comment:12 @pishmishy7 years ago

Ryan, patch for wp_dropdown_categories() now attached. Once applied, please close.

comment:13 @ryan7 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [6690]) Add depth arg to wp_dropdown_categories(). Props pishmishy. fixes #2461

Note: See TracTickets for help on using tickets.