WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#10703 closed enhancement (fixed)

Logarithmic scale for tag cloud tag size

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

Description

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 5 years ago.
Added callback, fixed the alt tag

Download all attachments as: .zip

Change History (8)

comment:1 kometbomb5 years ago

The difference can be seen here: http://kometbomb.net/tags/

comment:2 dd325 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.

comment:3 junsuijin5 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.

comment:4 scribu5 years ago

  • Keywords needs-patch added; has-patch removed

I've put it on my site: http://scribu.net/tags

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).

kometbomb5 years ago

Added callback, fixed the alt tag

comment:5 kometbomb5 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.

comment:6 azaozz5 years ago

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

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

comment:7 dougal5 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.