Coming uo with solutions to WordPress needs often means finding a different tree to bark at. I’m never surprised to discover along the way some dusty niche in the code.
For example, in the tale I spin out here, I never knew there was a limit for the number of tags the default tag cloud widget can show. And was it usually happens, this came via a request for one of my SPLOT themes where it’s being used in a way I never thought.
In this case, the situation is a course where students in multiple sections are contributing drawings to a TRU Collector powered site hosted at the OpenETC (see this clever SPLOTTING at Get Cape. Wear Cape. Fly). In the true SPLOT spirit of students not having to attach their name publically to submitted assignments, the instructor has assigned each student a unique tag they are asked to use on each submission.
The email I got came in with s subject line “SPLOTs not showing all tags”.
The problem arose because the instructor noticed that not all of the tags were listed on the site’s tag cloud widget sidebar. And hah, I never knew this, but this widget caps the number of tags shown at 45. Why? I can only guess it has something to do with not letting a widget get to take up gobs of space.
If it was a self hosted site, one way around is a different plugin, something like Ultimate Tag Cloud Widget which I used once. Maybe not, it’s pretty ancient. But plugins are less viable in a shared hosting environment, and often just end up being more piles of code than you need.
My first thought was to make used of some found code to change that number (bless the WordPress filer system), and I could see it being a new theme option.
It helps to let ideas simmer before jumping too quickly to a fix. What the need was not as much more tags in the sidebar, but actually what makes more sense is a means to generate in a page a list of all tags, something to be used to review student work.
So I decided to roll a shortcode function into my theme, that allows a site owner to create a list of tags but with options to display in many ways.
The code is simple and came mostly from reading up in the WordPress Codex on the get_tags
function (more or less a version of get_terms()
).
// Output a list of all tags add_shortcode("taglist", "trucollector_taglist"); function trucollector_taglist( $atts ) { extract(shortcode_atts( array( "number" => '0', "show_count" => true, "orderby" => 'name', "order" => "ASC", "hide_empty" => 1 ), $atts )); // set args $tags = get_tags(array( 'number' => $number, 'count' => $show_count, 'orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, )); if ($tags) { $output = '
- ';
foreach ($tags as $tag) {
$output .= '
- '. $tag->name .''; if ($show_count) $output .= ' (' . $tag->count . ')'; $output .= ' '; } $output .= '
No tags found!
'; } return $output; }The most simple version using all the defaults lists all tags used in alphabetical order, each one linked to the archive, and includes the number of items/posts using it (see the list of All Stories for Get Cape. Wear Cape. Fly).
[[taglist]]
You can see it in action on a test page over at https://splot.ca/collector/taglist/
One could list them instead in the order of most used to least:
[[taglist orderby="count" order="DESC"]]
And then by limiting the number shown, it could be a top 10 tag list.
[[taglist number="10" orderby="count" order="DESC"]]
This now seems much more useful than a tag cloud. And I am pretty sure the cutoff at 45 is not for the mst used, just the first 45.
This feature is available now in the latest version of the TRU Collector in GitHub and because I could, it is available to sites hosted at the OpenETC. I will likely toss the code into some of the other SPLOTs.
Thoughts, ideas, requests or even random GIFs of dancing elephants are welcome. Better yet, asl me for a new feature… you just might get it.
Featured Image:
I like it! I remember Ultimate Tag Cloud from back in the day. So nice to reflect on historical plugins with someone else. 🙂
I loved this plugin. But it was throwing an unidentified variable error on this line: $output .= ”;
Got suggestions?
Thanks
Thanks for this! Sloppy PHP that worked before, the line to initialize output should not have
.=
but just=
Corrected above and also in the source of the TRU Collector theme (not a plugin).