WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#33565 closed enhancement (fixed)

Add option to pass an array of objects or IDs to $current_category in wp_list_categories()

Reported by: vilkatis Owned by: boonebgorges
Milestone: 4.4 Priority: normal
Severity: normal Version: 4.4
Component: Taxonomy Keywords: has-patch
Focuses: Cc:
PR Number:

Description

I needed to pass an array of objects to $current_category a couple of times, and had to make a custom walker for that.
Would be nice if it was a part of core.

Attachments (3)

category-template.php.diff (2.7 KB) - added by vilkatis 4 years ago.
33565.diff (4.6 KB) - added by vilkatis 4 years ago.
Added unit tests
33565.2.diff (2.2 KB) - added by boonebgorges 4 years ago.

Download all attachments as: .zip

Change History (12)

#1 @vilkatis
4 years ago

  • Keywords has-patch needs-testing added

#2 @boonebgorges
4 years ago

Patch seems OK to me. Any chance you could take a swing at writing a few unit tests for it?

Out of curiosity, what is the use case for having more than one current_category?

@vilkatis
4 years ago

Added unit tests

#3 follow-up: @vilkatis
4 years ago

I added two unit tests that I could think of , don't know if that's enough or if I did them right.

I used it for some clients who had products belonging to a couple of categories at the same time , as they wanted all relevant categories to be highlighted in a sidebar menu.

#4 @boonebgorges
4 years ago

  • Owner set to boonebgorges
  • Resolution set to fixed
  • Status changed from new to closed

In 33767:

Rename param added to wp_list_categories() in [33764] to 'hide_title_if_empty'.

Props vilkatis, DrewAPicture.
Fixes #33565.

#5 follow-up: @SergeyBiryukov
4 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

[33767] was for #33460.

#6 in reply to: ↑ 5 @boonebgorges
4 years ago

Replying to SergeyBiryukov:

[33767] was for #33460.

Gah.

#7 in reply to: ↑ 3 @boonebgorges
4 years ago

  • Milestone changed from Awaiting Review to 4.4

Replying to vilkatis:

I added two unit tests that I could think of , don't know if that's enough or if I did them right.

I used it for some clients who had products belonging to a couple of categories at the same time , as they wanted all relevant categories to be highlighted in a sidebar menu.

Thanks, this seems sensible.

Looking at it more closely, I don't think that it's a great idea for us to start accepting term objects in addition to term IDs. There aren't many places where we do this for terms (at least not that I can think of). When and if we have a proper WP_Term object, perhaps we can start thinking of retrofitting functions to accept it.

I've simplified the patch and the unit tests in 33565.2.diff.

@boonebgorges
4 years ago

#8 @vilkatis
4 years ago

  • Keywords needs-testing removed

Yeah that looks great , thanks for the help ! Passing term IDs makes the most sense indeed

#9 @boonebgorges
4 years ago

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

In 33804:

In wp_list_categories(), 'current_category' should accept an array of values.

This allows the 'current-cat' or 'current-cat-parent' classes to be applied
to more than one item in the list.

Props vilkatis.
Fixes #33565.

Note: See TracTickets for help on using tickets.