Make WordPress Core

Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#10703 closed enhancement (fixed)

Logarithmic scale for tag cloud tag size

Reported by: kometbomb's profile kometbomb Owned by:
Milestone: 2.9 Priority: normal
Severity: normal Version: 2.8.4
Component: Template Keywords: has-patch
Focuses: Cc:


The tag clouds generated by wp_tag_cloud() tend to work poorly if there's one or two dominant tags, i.e. the tag could has very many small tags and one or two huge tags. This can be avoided by not resizing the tags by the normalized absolute post count but by the normalized log10 of the count. This makes the offending "peak" tags smaller.

Here's a patch that adds a new boolean arg for wp_tag_cloud() called 'logarithmic'. The default is false which makes wp_tag_cloud() generate the same cloud as before, setting the arg to true makes wp_tag_cloud() generate a tag cloud with the tag sizes based on log10.

Attachments (1)

logarithmic_tag_cloud.diff (2.1 KB) - added by kometbomb 15 years ago.
Added callback, fixed the alt tag

Download all attachments as: .zip

Change History (8)

#1 @kometbomb
15 years ago

The difference can be seen here:

#2 @dd32
15 years ago

  • Keywords has-patch added; tag cloud tags removed
  • Milestone changed from Unassigned to 2.9

Looking purely at the example you've given, i'd actually support making log10 the default.

#3 @junsuijin
15 years ago

+1 dd32's suggestion. If this logarithmic sizing is included though, maybe shorten it from 'logarithmic' to just 'log10'. I think a better option, if the an extra parameter like 'logarithmic' is desirable, is to have log10 be the default, and provide the ability to give any callback function name as the scale determination factor.

#4 @scribu
15 years ago

  • Keywords needs-patch added; has-patch removed

I've put it on my site:

And I also think it should be the default.

However, with the current patch, the displayed count is also inflated.

For example: hovering over Viewer2 tag shows "136 topics" with log10 and "22 topics" without (the real number).

15 years ago

Added callback, fixed the alt tag

#5 @kometbomb
15 years ago

  • Keywords has-patch added; needs-patch removed

Ok, thanks for your input. I fixed the issue with the alt text and added a callback parameter (topic_count_scale_callback). Also, it now defaults to log10 since I detected some sort of consensus.

#6 @azaozz
15 years ago

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

(In [11894]) Logarithmic scale for tag cloud, props kometbomb, fixes #10703

#7 @dougal
15 years ago

Awesome. The bad results for long-tail tags has always bugged me, and I kept meaning to do something like this myself. But I didn't think of using a log function for the scaling. Much simpler than what I had in mind, which was to just linearly scale the tags in their count order (as opposed to the count value).

Note: See TracTickets for help on using tickets.