Make WordPress Core

Opened 11 years ago

Closed 9 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 11 years ago.
tag_cloud_smart.jpg (77.0 KB) - added by PStamatiou 10 years ago.
4552.smartclip.diff (1.7 KB) - added by DD32 10 years ago.
Clips lower items first(limitmode=smart), moves links into wp_tag_cloud()

Download all attachments as: .zip

Change History (17)

#1 @pgdx
11 years ago

Should be fixed with something like this

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

11 years ago

#2 @pgdx
11 years ago

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

#3 @pgdx
11 years ago

Thanks to spencerp who found the bug!

#4 @westi
11 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Leave open till committed

#5 @foolswisdom
11 years ago

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

#6 @PStamatiou
10 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

10 years ago

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

#7 @DD32
10 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 :)

#8 @ryan
10 years ago

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

#9 @mdawaffe
10 years ago

I can't reproduce the bug.

#10 @ryan
10 years ago

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

#11 @Nazgul
10 years ago

  • Milestone 2.3 deleted

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

#13 @Otto42
10 years ago

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

#14 @DD32
9 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.