Make WordPress Core

Opened 8 years ago

Closed 6 years ago

#4552 closed defect (bug) (fixed)

number argument in wp_generate_tag_cloud is not used

Reported by: pgdx Owned by: ryan
Milestone: 2.7 Priority: normal
Severity: normal Version: 2.3
Component: Template Keywords: tag cloud number wp_tag_cloud has-patch
Focuses: Cc:


When using the wp_tag_cloud function the argument "number" is ignored, specifically in the function wp_generate_tag_cloud.

Attachments (3)

ticket4552 (650 bytes) - added by pgdx 8 years ago.
tag_cloud_smart.jpg (77.0 KB) - added by PStamatiou 8 years ago.
4552.smartclip.diff (1.7 KB) - added by DD32 8 years ago.
Clips lower items first(limitmode=smart), moves links into wp_tag_cloud()

Download all attachments as: .zip

Change History (17)

comment:1 @pgdx8 years ago

Should be fixed with something like this

$numbers = 0;
foreach ( $counts as $tag => $count ) {
   if ($numbers++ >= $number)

@pgdx8 years ago

comment:2 @pgdx8 years ago

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

comment:3 @pgdx8 years ago

Thanks to spencerp who found the bug!

comment:4 @westi8 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Leave open till committed

comment:5 @foolswisdom8 years ago

  • Component changed from Administration to Template
  • Keywords has-patch added

@PStamatiou8 years ago

comment:6 @PStamatiou8 years ago

While this code does work for me, I was hoping for a method of limiting tags in a tag cloud on a slightly different basis. By just limiting a tag cloud to say 20 tags, for use in a sidebar for example, it just takes out tags from the bottom regardless of their importance. I'm aware that they can be ordered asc/desc and by name/count, but I would like to see a way that retains the tag cloud appearance while limiting the number of tags.

That is, perhaps another parameter, or just the logic to limit tags by not displaying ones that have very few posts associated with them and rescaling the remaining tags' sizes to still have the trademark "tag cloud" appearance

crude mockup to illustrate my jargon: http://paulstamatiou.com/files/tag_cloud_smart.jpg

@DD328 years ago

Clips lower items first(limitmode=smart), moves links into wp_tag_cloud()

comment:7 @DD328 years ago

Just added my contribution to this, Its designed to do 3 things:

  • Smart clipping by default, Removes items with less number of topics and retains the higher-valued tags, Allows it to retain the same A-Z view, yet limit it to a smaller number of items
  • Moved WP Tag links into wp_tag_cloud(), Allows wp_generate_tag_cloud() to be used for other purposes than the WP Tagging functions.
  • Further on that previous one, $tags can be an object, or array

Seems to work as i intended, But with all the sorting thats going on :)

comment:8 @ryan8 years ago

  • Owner changed from pgdx to ryan
  • Status changed from reopened to new

comment:9 @mdawaffe7 years ago

I can't reproduce the bug.

comment:10 @ryan7 years ago

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

comment:11 @Nazgul7 years ago

  • Milestone 2.3 deleted

comment:12 @Otto427 years ago

  • Milestone set to 2.4
  • Resolution worksforme deleted
  • Status changed from closed to reopened

This bug is easily reproducible, just badly described.

wp_generate_tag_cloud() does not use the number argument even though it's in the defaults for the function. Call wp_generate_tag_cloud($tags, "number=1") and you get back more than one tag.

Whether this should be fixed or not is up for debate. As I see it, you should limit the number of tags when you call get_tags(), before passing them to the generator function. This is what wp_tag_cloud() does.

So my suggested fix is simply to remove "number" as an option from the defaults in wp_generate_tag_cloud(). It doesn't use $number anywhere and it seems pointless to do so, if you want less tags, pass in a smaller number of tags to begin with.

comment:13 @Otto427 years ago

  • Summary changed from number argument in wp_tag_cloud is ignored to number argument in wp_generate_tag_cloud is not used

comment:14 @DD326 years ago

  • Milestone changed from 2.9 to 2.7
  • Resolution set to fixed
  • Status changed from reopened to closed

The number param was fixed during 2.7's dev cycle. wp_generate_tag_cloud() which is used by wp_tag_cloud() now respects the $number arg.

Note: See TracTickets for help on using tickets.