Make WordPress Core

Opened 6 years ago

Last modified 9 months ago

#10676 new enhancement

current-cat-ancestor in wp_list_categories

Reported by: spathon Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 2.8.5
Component: Taxonomy Keywords: has-patch needs-testing 2nd-opinion
Focuses: Cc:


The wp_list_categories should apply current-cat-ancestor like wp_list_pages not just current-cat-parent to the closest parent

Attachments (3)

category-template-10676.diff (752 bytes) - added by ardathksheyna 2 years ago.
10676.diff (799 bytes) - added by wonderboymusic 2 years ago.
10676_short_circuit.diff (822 bytes) - added by jrchamp 15 months ago.

Download all attachments as: .zip

Change History (15)

comment:1 @spathon6 years ago

  • Milestone changed from Future Release to 2.9
  • Version changed from 2.8.4 to 2.8.5

comment:2 @azaozz6 years ago

  • Milestone changed from 2.9 to Future Release

No patch.

comment:3 @ardathksheyna2 years ago

  • Cc jgreen@… added

comment:4 @ardathksheyna2 years ago

  • Keywords has-patch needs-testing added

comment:5 @DrewAPicture2 years ago

  • Component changed from General to Taxonomy
  • Keywords class categories removed

@wonderboymusic2 years ago

comment:6 @wonderboymusic2 years ago

  • Milestone changed from Future Release to 3.7

10676.diff​ rehabs the whitespace

comment:7 @nacin2 years ago

Two considerations here:

  • Are the ancestor queries OK and worth it?
  • Does the class name we're going with make sense?

comment:8 @nacin2 years ago

  • Type changed from feature request to enhancement

comment:9 @nacin2 years ago

  • Keywords 2nd-opinion added
  • Milestone changed from 3.7 to Future Release

Punting pending answers to the two questions.

comment:10 @jrchamp15 months ago

The class name makes sense. It's the logical conclusion given that I reimplemented it before finding this ticket.

I dislike the use of get_ancestors() because it has extra overhead, we already have the first term and only need to check the terms until the point that it matches. I'm attaching a modified version of this patch that doesn't waste time array_reversing and leverages the short circuit opportunities to often avoid the get_ancestors() call altogether.

Really, given the inherent static response given by the get_ancestors() call for the provided current_category, if the Walker_Category object initialized a private member variable with the get_ancestors() array the first time it was needed, you could easily use a simple isset on the member variable on all subsequent calls. Additionally, if this path were pursued I would recommend an array_flip to allow use of the isset language construct on the array of ancestor IDs itself rather than the much slower in_array() function.

comment:11 @SergeyBiryukov9 months ago

#30635 was marked as a duplicate.

Note: See TracTickets for help on using tickets.