Make WordPress Core

Opened 12 years ago

Last modified 5 years ago

#21165 reopened enhancement

Make categories widget work with custom taxonomies

Reported by: scribu's profile scribu Owned by: wonderboymusic's profile wonderboymusic
Milestone: 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 (9)

21165.diff (3.2 KB) - added by fonglh 12 years ago.
21165.2.diff (5.2 KB) - added by fonglh 12 years ago.
Second draft. Fixed issues mentioned by scribu.
21165.3.diff (5.2 KB) - added by fonglh 12 years ago.
Changed default value of 'select_name' label from 'Select Taxonomy' to 'Select Category'
21165.4.diff (4.8 KB) - added by fonglh 12 years ago.
Changed description back to original wording
21165.5.diff (4.5 KB) - added by fonglh 12 years ago.
Removed value of 'select_name' for category as it is the same as the default value
21165.6.diff (3.3 KB) - added by wonderboymusic 9 years ago.
21165.7.diff (3.9 KB) - added by DrewAPicture 9 years ago.
escaping + docblock
21165.8.diff (5.4 KB) - added by kucrut 9 years ago.
Refresh patch
21165.png (79.2 KB) - added by kucrut 9 years ago.
Widget form

Download all attachments as: .zip

Change History (41)

@fonglh
12 years ago

#1 @fonglh
12 years ago

  • Keywords has-patch added

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

#2 follow-up: @scribu
12 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;

#3 @scribu
12 years ago

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

@fonglh
12 years ago

Second draft. Fixed issues mentioned by scribu.

#4 follow-up: @fonglh
12 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'.

#5 in reply to: ↑ 2 ; follow-up: @kobenland
12 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 12 years ago by kobenland (previous) (diff)

#6 follow-up: @kobenland
12 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...

#7 in reply to: ↑ 5 @SergeyBiryukov
12 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.

#8 in reply to: ↑ 4 @scribu
12 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'.

Last edited 12 years ago by scribu (previous) (diff)

@fonglh
12 years ago

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

#9 in reply to: ↑ 6 @fonglh
12 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.

#10 @scribu
12 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.

#11 @fonglh
12 years ago

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

#12 @scribu
12 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.

@fonglh
12 years ago

Changed description back to original wording

#13 @fonglh
12 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 12 years ago by fonglh (previous) (diff)

#14 @scribu
12 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	                ), 

@fonglh
12 years ago

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

#15 @fonglh
12 years ago

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

#16 @nacin
12 years ago

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

#17 @scribu
12 years ago

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

#18 @nacin
12 years ago

  • Milestone changed from 3.5 to Future Release

#19 @tar.gz
12 years ago

  • Cc code@… added

@DrewAPicture
9 years ago

escaping + docblock

#21 @DrewAPicture
9 years ago

  • Milestone changed from Future Release to 4.4

21165.7.diff adds escaping, simplifies the foreach for the select, and adds a DocBlock for the utility method.

This ticket was mentioned in Slack in #core by sergey. View the logs.


9 years ago

#23 @SergeyBiryukov
9 years ago

  • Keywords needs-refresh added

#24 @SergeyBiryukov
9 years ago

  • Keywords needs-screenshots added

A screenshot would also be nice.

@kucrut
9 years ago

Refresh patch

@kucrut
9 years ago

Widget form

#25 @kucrut
9 years ago

  • Keywords needs-refresh needs-screenshots removed

21165.8.diff refreshes 21165.7.diff and adds the select_name taxonomy label.

#26 @wonderboymusic
9 years ago

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

In 34376:

Widgets: Make the categories widget work with custom taxonomies.

Props fonglh, wonderboymusic, DrewAPicture, kucrut.
Fixes #21165.

#27 @DrewAPicture
9 years ago

In 34386:

Docs: Add a changelog entry to WP_Widget_Categories for non-category support, added in [34376].

See #21165. See #32246.

#28 follow-up: @helen
9 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

I had anticipated that this would be awkward, which is why I had asked for screenshots.

  • The widget is still labeled "Categories" - yes, the one for tags is labeled "Tag Cloud", but the descriptor of what the UI is makes it quite different.
  • The restriction to hierarchical taxonomies is strange from a user perspective seeing as it's not restricted that way for tag clouds.
  • The way the restriction is done in the code is also strange - should be passed as an arg to get_taxonomies() instead of retrieving everything and then skipping.
  • I also don't see much of a way for a taxonomy not to be shown in these selects - tag cloud has a show_tagcloud arg when registering a taxonomy.

#29 @DrewAPicture
9 years ago

  • Keywords revert added

Citing feedback from @helen in comment:28, I think we should probably revert [34376] and [34386] and fall-back and regroup.

I played around with it a little bit 2 weeks ago and there's definitely some work to be done yet. We could add another argument, e.g. show_categories_widget but that doesn't really make sense.

I also played around with the idea of deprecating the show_tagcloud argument in favor of a new show_in_widgets argument that accepts an array (would control what show_tagcloud does now, plus the categories widget). Ended up being a lot of code for a simple task.

Then we have the problem of this being called the "Categories" widget.

#30 @wonderboymusic
9 years ago

In 35278:

Widgets: revert [34376] and [34386] as pertains to the Categories widget supporting custom taxonomies.

Punting on 4th down.

See #21165.

#31 @wonderboymusic
9 years ago

  • Keywords revert removed
  • Milestone changed from 4.4 to Future Release

#32 in reply to: ↑ 28 @ericlewis
9 years ago

Replying to helen:

  • The widget is still labeled "Categories" - yes, the one for tags is labeled "Tag Cloud", but the descriptor of what the UI is makes it quite different.

Should we change the name of the Categories widget to "Taxonomy terms," and description to "A list or dropdown of terms in a taxonomy"? This may be foreign terminology for users but if the widget type is becoming tax-agnostic we should probably describe it as such.

Note: See TracTickets for help on using tickets.