Opened 5 years ago

Last modified 4 years ago

#5770 reopened enhancement

Add extra options for default tag-cloud widget

Reported by: AndrewFrazier Owned by:
Priority: low Milestone: Future Release
Component: Widgets Version: 2.5
Severity: minor Keywords: has-patch needs-testing
Cc:

Description

The default tag cloud widget only allows changing the title that appears above the tag cloud in the sidebar.

This patch allows use of more configurable options in wp_tag_cloud(), ie smallest, largest, unit, number, format, orderby, order.

Attachments (7)

widget.php.diff (5.5 KB) - added by AndrewFrazier 5 years ago.
widgets.php.diff (5.5 KB) - added by AndrewFrazier 5 years ago.
Same file, proper spelling this time
widgets.php_8180-5770.diff (4.6 KB) - added by AndrewFrazier 5 years ago.
Slightly tweaked version of the patch, based on revision 8180
5770.diff (4.4 KB) - added by DD32 5 years ago.
default-widgets.php_11391-5770.diff (9.4 KB) - added by AndrewFrazier 4 years ago.
Updated patch
default-widgets.php_11411-5770.diff (8.6 KB) - added by AndrewFrazier 4 years ago.
Updated patch, two options removed to shorten the list
default-widgets.php_11605-5770.diff (3.9 KB) - added by AndrewFrazier 4 years ago.
Updated patch. Fixes bugs.

Download all attachments as: .zip

Change History (40)

Same file, proper spelling this time

  • Keywords has-patch added; tag-cloud widget removed
  • Milestone changed from 2.5 to 2.6

What are the odds of this patch being included in 2.5.1, or at all?

Its been several months. Is there any way that this patch could be merged with the trunk, or updated if necessary?

As the beta of 2.6 is imminent, is there any chance of this getting included? Or at least, if it's not going in, of someone coming along and telling me my code sucks?

comment:6 follow-up: ↓ 7   DD325 years ago

Or at least, if it's not going in, of someone coming along and telling me my code sucks?

Cant say why its not gone in, However, On your code:

  • $optionss should probably be merged with $args somehow
  • Theres no need to translate defaults( __() and _e() are translatable strings)
  • For defaults, Look into wp_parse_args() and the way $defaults are used elsewhere.

Finally: I was going to update your patch so it took into consideration those, But the patch needs to be refreshed(recreated) on a later branch, As it is, The patcher is getting confused as to which changes need to be made..

comment:7 in reply to: ↑ 6   AndrewFrazier5 years ago

  • Theres no need to translate defaults( __() and _e() are translatable strings)

I did that to be consistent with what was already there.

I'll have an updated patch available shortly based on revision 8180.

comment:8   DD325 years ago

  • Theres no need to translate defaults( () and _e() are translatable strings)

I did that to be consistent with what was already there.

Ah, Well, I meant theres no need to translate non-string defaults, Ie. "tags" or "Default Header" would be translated, But anything that is constant between languages (such as size, measurements, etc) dont need to be.

Slightly tweaked version of the patch, based on revision 8180

I've stripped out the () from around the defaults.

attachment 5770.diff added.

Just a patch showing how i'd personally write it.

DD325 years ago

That way works well. The text inputs look better with the class on them, too.

  • Component changed from Administration to Widgets
  • Owner anonymous deleted
  • Resolution set to fixed
  • Status changed from new to closed

patch needs a refresh, too.

  • Resolution fixed deleted
  • Status changed from closed to reopened

woops, seems like keyboard shortcuts led me to close this...

  • Keywords needs-patch added; has-patch removed
  • Milestone 2.9 deleted
  • Resolution set to invalid
  • Status changed from reopened to closed

The current setup makes things simple: The user doesn't need to ask himself questions. If there is a need to override any or all of this, a plugin can easily be written. Or a filter can be added in the theme's functions.php file, on widget_tag_cloud_args.

comment:18 in reply to: ↑ 17   andrewfrazier4 years ago

Replying to Denis-de-Bernardy:

a plugin can easily be written

Not true.

Seriously, I can't find anything in the codex that even hints at how I might add options to an existing widget.

Or a filter can be added in the theme's functions.php file, on widget_tag_cloud_args.

And, if a function is added to the theme it's not going to affect the widget page of the admin area is it? Wouldn't it mean that a user would have to edit the functions.php file any time that he wanted to change any of the options?

like this:

add_filter(widget_tag_cloud_args, your_function)

then, there are two hooks that let you add to the form:

		// filters the widget admin form before displaying, return false to stop displaying it
		$instance = apply_filters('widget_form_callback', $instance, $this);

		$return = null;
		if ( false !== $instance ) {
			$return = $this->form($instance);
			if ( 'noform' !== $return )
				do_action_ref_array( 'in_widget_form', array(&$this) ); // add extra fields in the widget form
		}
		return $return;

and finally, there is a two hook that let you fetch the options that were sent:

	$instance = apply_filters('widget_update_callback', $instance, $new_instance, $this);
	if ( false !== $instance )
		$all_instances[$number] = $instance;

Thanks for the prompt reply and hints.

It becomes clear to me that it is too complex for my comprehension so I shall give up.

  • Milestone set to 2.8
  • Priority changed from normal to low
  • Resolution invalid deleted
  • Severity changed from normal to minor
  • Status changed from closed to reopened

let's re-open it, then. an option or two could probably be useful in a future release (or now, if someone refreshes dion's patch)

  • Milestone changed from 2.8 to Future Release

Setting to future pending patch. Tag clouds are so passé now anyway. :-)

Updated patch

  • Keywords has-patch needs-testing added; needs-patch removed

Updated the patch, it works for me but probably needs further testing.

Tag clouds may be passé but they still get used, and it should be easier to use the options that are available for it, IMO.

Do we really need *all* of those options? :-|

You could probably get by without minimum size and unit, but I think the others are useful.

Updated patch, two options removed to shorten the list

  • Milestone changed from Future Release to 2.9
  • Keywords needs-patch added; has-patch needs-testing removed
  • Milestone changed from 2.9 to Future Release

broken patch

Updated patch. Fixes bugs.

  • Keywords has-patch needs-testing added; needs-patch removed
  • Milestone changed from Future Release to 2.9

Can I suggest only adding two options, taxonomy and number? The other options seem to give the impression we're really coding:

  • Order by name should automatically imply ASC; order by number should automatically imply DESC.
  • It seems like it would be better to change the default args for the tag cloud for the size if 22pt is too large

On a separate note, when number is set, does it take the first N tags, or those with the highest term count. If the former, we may want to change the behavior to the latter.

Well, maybe order might be good too, but the ASC/DESC definitely doesn't belong in there imo.

I'm having trouble working out just how number works; It appears to be the first N tags but irrelevant of whatever other options that may be set. IMO the other options should be applied first then the number last but this doesn't seem to be the case. It may be possible to fix by editing the wp-generate_tag_cloud function in category_template.php, moving

	if ( $number > 0 )
		$tags = array_slice($tags, 0, $number);

from lines 640/641 down below

	$font_step = $font_spread / $spread;

on line 654, but I haven't tested yet.

With regard to the ordering, as the default is "ASC" (no matter what other options are set) you could change the Order dropdown to a checkbox for reverse order.

No, moving that block of text doesn't work. It appears that setting Number selects the first N tags based on the order in which they were created, which IMO opinion is just plain wrong, but I haven't tracked down the block of code that performs this action to confirm.

  • Milestone changed from 2.9 to Future Release

Punting due to feature freeze.

Note: See TracTickets for help on using tickets.