WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 2 years ago

#21165 new enhancement

Make categories widget work with custom taxonomies

Reported by: scribu Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Widgets Keywords: has-patch
Focuses: Cc:

Description

The tag cloud widget already has a taxonomy dropdown.

We should add one for the categories widget as well.

Attachments (5)

21165.diff (3.2 KB) - added by fonglh 3 years ago.
21165.2.diff (5.2 KB) - added by fonglh 3 years ago.
Second draft. Fixed issues mentioned by scribu.
21165.3.diff (5.2 KB) - added by fonglh 3 years ago.
Changed default value of 'select_name' label from 'Select Taxonomy' to 'Select Category'
21165.4.diff (4.8 KB) - added by fonglh 3 years ago.
Changed description back to original wording
21165.5.diff (4.5 KB) - added by fonglh 3 years ago.
Removed value of 'select_name' for category as it is the same as the default value

Download all attachments as: .zip

Change History (24)

@fonglh3 years ago

comment:1 @fonglh3 years ago

  • Keywords has-patch added

First draft. Replicated taxonomy dropdown of the tag cloud widget to the categories widget.

comment:2 follow-up: @scribu3 years ago

Hey fonglh, thanks for the patch. There are two issues with it, though:

  1. The $tax->show_tagcloud check is not appropriate. I think we could use $tax->is_hierarchical instead.
  1. Some translations need to change the order of the words, so appending strings doesn't work well for them:
__('Select ') . get_taxonomy( $current_taxonomy )->labels->singular_name;

I guess we'll have to introduce a new 'select' label to register_taxonomy(), so that we can do this:

get_taxonomy( $current_taxonomy )->labels->select;

comment:3 @scribu3 years ago

Oh, and duck_ pointed out that _get_current_taxonomy() should default to 'category' not 'categories'.

@fonglh3 years ago

Second draft. Fixed issues mentioned by scribu.

comment:4 follow-up: @fonglh3 years ago

Hey scribu, thanks for the feedback. I've fixed the issues you mentioned.

For the second one, I've introduced a new label 'select_name' with a default value of 'Select Taxonomy'.

comment:5 in reply to: ↑ 2 ; follow-up: @kobenland3 years ago

Replying to scribu:

I guess we'll have to introduce a new 'select' label to register_taxonomy(), so that we can do this:

get_taxonomy( $current_taxonomy )->labels->select;

Why not do

<?php
sprintf( _x( 'Select %s', 'taxonomy singular name' ), get_taxonomy( $current_taxonomy )->labels->singular_name );
Last edited 3 years ago by kobenland (previous) (diff)

comment:6 follow-up: @kobenland3 years ago

On a different note:

This is the Category Widget we're talking about - not the Taxonomy Widget. It would make more sense, if we'd make a separate widget for it. And with it being a separate Widget, it'd be debatable whether this is better released as a Plugin...

comment:7 in reply to: ↑ 5 @SergeyBiryukov3 years ago

Replying to kobenland:

<?php
sprintf( _x( 'Select %s', 'taxonomy singular name' ), get_taxonomy( $current_taxonomy )->labels->singular_name );

A simple sprintf() is not enough due to different grammatical cases, see ticket:19099:1 or ticket:17609:3.

comment:8 in reply to: ↑ 4 @scribu3 years ago

Replying to fonglh:

For the second one, I've introduced a new label 'select_name' with a default value of 'Select Taxonomy'.

'Select Taxonomy' isn't correct, because the dropdown won't contain taxonomies, but terms. So, a more accurate default would be 'Select Term'.

But, since the other default labels use 'Category' instead of 'Term, I think we should stick to 'Select Category'.

Version 0, edited 3 years ago by scribu (next)

@fonglh3 years ago

Changed default value of 'select_name' label from 'Select Taxonomy' to 'Select Category'

comment:9 in reply to: ↑ 6 @fonglh3 years ago

  • Cc fonglh added

Replying to kobenland:

On a different note:

This is the Category Widget we're talking about - not the Taxonomy Widget. It would make more sense, if we'd make a separate widget for it. And with it being a separate Widget, it'd be debatable whether this is better released as a Plugin...

Since categories are treated as a type of taxonomy, maybe it'll be better to rename the widget the Taxonomy Widget instead? I don't think there's a need for 2 widgets.

comment:10 @scribu3 years ago

Conversely, to the average user, a hierarchical taxonomy is just another set of categories. We should keep the "Categories" name for the widget.

comment:11 @fonglh3 years ago

Ok then, is there anything else that has to be improved?

comment:12 @scribu3 years ago

The description confuses terms and taxonomies again:

"A list or dropdown of categories or custom taxonomies"

Correct would be:

"A list or dropdown of categories or of custom taxonomy terms"

although I'm not sure it's necessary. The tag cloud widget doesn't mention custom taxonomies either.

@fonglh3 years ago

Changed description back to original wording

comment:13 @fonglh3 years ago

I decided to leave the wording as it currently is:

"A list or dropdown of categories"

The correct version seems to be a bit of a mouthful, although it's a more accurate description.

Last edited 3 years ago by fonglh (previous) (diff)

comment:14 @scribu3 years ago

  • Milestone changed from Awaiting Review to 3.5

Ok, just one more thing: These lines are not necessary anymore:

	46	                'labels' => array( 
 	47	                        'select_name' => __( 'Select Category' ) 
 	48	                ), 

@fonglh3 years ago

Removed value of 'select_name' for category as it is the same as the default value

comment:15 @fonglh3 years ago

Ok, I've removed them from the function call of register_taxonomy() when 'category' is registered.

comment:16 @nacin3 years ago

I don't mind this, but I wish we could get away without a new taxonomy label for it.

comment:17 @scribu3 years ago

Maybe we could get away with an empty 'show_option_none'.

comment:18 @nacin2 years ago

  • Milestone changed from 3.5 to Future Release

comment:19 @tar.gz2 years ago

  • Cc code@… added
Note: See TracTickets for help on using tickets.