Make WordPress Core

Opened 6 years ago

Last modified 12 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 18 months ago.

Download all attachments as: .zip

Change History (15)

#1 @spathon
6 years ago

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

#2 @azaozz
6 years ago

  • Milestone changed from 2.9 to Future Release

No patch.

#3 @ardathksheyna
2 years ago

  • Cc jgreen@… added

#4 @ardathksheyna
2 years ago

  • Keywords has-patch needs-testing added

#5 @DrewAPicture
2 years ago

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

2 years ago

#6 @wonderboymusic
2 years ago

  • Milestone changed from Future Release to 3.7

10676.diff​ rehabs the whitespace

#7 @nacin
2 years ago

Two considerations here:

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

#8 @nacin
2 years ago

  • Type changed from feature request to enhancement

#9 @nacin
2 years ago

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

Punting pending answers to the two questions.

#10 @jrchamp
18 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.

#11 @SergeyBiryukov
12 months ago

#30635 was marked as a duplicate.

Note: See TracTickets for help on using tickets.