Opened 6 years ago
Closed 4 years ago
#4552 closed defect (bug) (fixed)
number argument in wp_generate_tag_cloud is not used
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 2.7 |
| Component: | Template | Version: | 2.3 |
| Severity: | normal | Keywords: | tag cloud number wp_tag_cloud has-patch |
| Cc: |
Description
When using the wp_tag_cloud function the argument "number" is ignored, specifically in the function wp_generate_tag_cloud.
Attachments (3)
Change History (17)
- Resolution fixed deleted
- Status changed from closed to reopened
Leave open till committed
comment:5
foolswisdom — 6 years ago
- Component changed from Administration to Template
- Keywords has-patch added
PStamatiou — 6 years ago
comment:6
PStamatiou — 6 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
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:10
ryan — 6 years ago
- Resolution set to worksforme
- Status changed from new to closed
comment:11
Nazgul — 6 years ago
- Milestone 2.3 deleted
comment:12
Otto42 — 6 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
Otto42 — 6 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
DD32 — 4 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.

Should be fixed with something like this
$numbers = 0; foreach ( $counts as $tag => $count ) { if ($numbers++ >= $number) break;