Tags are useful to any blog: As you know it, they allow the user to display a list of posts related to a subject.
Most of the time, tags are displayed with in a tag cloud. If you have 20 different tags, that’s ok, but if you have 100 or more tags your tag cloud will be very hard to read, and no-one will click on it.
This is probably why many blogs recently stopped displaying their tag cloud, or put it on a separate page. But I got another solution.
My wife owns a blog where she reviews books. She use tags to display author names, which is a great use of tags, in my opinion. The tags were first displayed as a list, and it was perfect. But after she reviewed 60+ books, the list started to be too long.
She asked me about a solution, and after some reflection, I came up with the idea of using a drop-down menu (select html element + a bit of javascript). Happily, I was able to found this code on WordPress forums.
First, we have to create a php function. Copy and paste the following code in the functions.php file of your theme (Be careful with the php opening/closing tags!)
<?php
function dropdown_tag_cloud( $args = '' ) {
$defaults = array(
'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',
'exclude' => '', 'include' => ''
);
$args = wp_parse_args( $args, $defaults );
$tags = get_tags( array_merge($args, array('orderby' => 'count', 'order' => 'DESC')) ); // Always query top tags
if ( empty($tags) )
return;
$return = dropdown_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args
if ( is_wp_error( $return ) )
return false;
else
echo apply_filters( 'dropdown_tag_cloud', $return, $args );
}
function dropdown_generate_tag_cloud( $tags, $args = '' ) {
global $wp_rewrite;
$defaults = array(
'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC'
);
$args = wp_parse_args( $args, $defaults );
extract($args);
if ( !$tags )
return;
$counts = $tag_links = array();
foreach ( (array) $tags as $tag ) {
$counts[$tag->name] = $tag->count;
$tag_links[$tag->name] = get_tag_link( $tag->term_id );
if ( is_wp_error( $tag_links[$tag->name] ) )
return $tag_links[$tag->name];
$tag_ids[$tag->name] = $tag->term_id;
}
$min_count = min($counts);
$spread = max($counts) - $min_count;
if ( $spread <= 0 )
$spread = 1;
$font_spread = $largest - $smallest;
if ( $font_spread <= 0 )
$font_spread = 1;
$font_step = $font_spread / $spread;
// SQL cannot save you; this is a second (potentially different) sort on a subset of data.
if ( 'name' == $orderby )
uksort($counts, 'strnatcasecmp');
else
asort($counts);
if ( 'DESC' == $order )
$counts = array_reverse( $counts, true );
$a = array();
$rel = ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) ? ' rel="tag"' : '';
foreach ( $counts as $tag => $count ) {
$tag_id = $tag_ids[$tag];
$tag_link = clean_url($tag_links[$tag]);
$tag = str_replace(' ', ' ', wp_specialchars( $tag ));
$a[] = "\t<option value='$tag_link'>$tag ($count)</option>";
}
switch ( $format ) :
case 'array' :
$return =& $a;
break;
case 'list' :
$return = "<ul class='wp-tag-cloud'>\n\t<li>";
$return .= join("</li>\n\t<li>", $a);
$return .= "</li>\n</ul>\n";
break;
default :
$return = join("\n", $a);
break;
endswitch;
return apply_filters( 'dropdown_generate_tag_cloud', $return, $tags, $args );
}
?>
Once you have your function, you must call it somewhere on your theme. Just open the file where you want the list to be displayed (Most of the time it is sidebar.php) and paste the following code:
<select name="tag-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;">
<option value="#">Liste d'auteurs</option>
<?php dropdown_tag_cloud('number=0&order=asc'); ?>
</select>
Now, you have a very cool drop-down list to display you tags. No more unreadables tag clouds!














There Are 48 Responses So Far »
Pingback: Display your WordPress Tags in a Drop-Down Menu | bloground.ro - Blogging resources, WordPress themes and plugins for your development
Pingback: Tags in Wordpress in einem Dropdown-Menü anzeigen | mlogger
Pingback: Como exibir tags em um menu dropdown | pBlog
Pingback: DigiZen » Tags presentados mediante menú desplegable
Pingback: [How-to] Mostrar los tags en menú desplegable | Tinta Fantasma
Pingback: 10 sehr interessante Wordpress Tutorials | Million-Maker.net
Pingback: 135+ Ultimate Round-Up of Wordpress Tutorials | About Us | instantShift
Pingback: Design History Lab: technical » Blog Archive » menu link
Pingback: 250 Wordpress Tutorials
Pingback: 135+ Ultimate Wordpress Tutorials
Pingback: WordPress hack: Display your tags in a dropdown menu
Pingback: Anime Dropdown Widget
Pingback: Display your tags in a dropdown menu | WPThemes.com - WordPress Themes
Pingback: Tampilkan Tag Dalam Bentuk Dropdown | Tarqy dot Com
Pingback: WordPress hack: Display your tags in a dropdown menu | Quest For News, A TUTORIAL Base
Pingback: WordPress hack: Mostra suas tags em um menu dropdown | Ajuda Wordpress em Português
Pingback: Címkék legördül? menüben | WordPress blog és weboldal készítés
Pingback: Wordpress:Etiketleri Aç?lan Menüde Gösterme | DownloadSEN
Pingback: Menampilkan Dropdown Tags Cloud WordPress « andelumut
Pingback: Menampilkan Dropdown Tags Cloud WordPress | Balisugar
Pingback: 13 Useful Code Snippets for WordPress Development | Web Design Ledger
Pingback: 37 Cool Wordpress Hacks And Tutorials You Should Try |
Pingback: 37 Cool Wordpress Hacks And Tutorials You Should Try | Afif Fattouh - Web Specialist
Pingback: 37?Wordpress???? | ???
Pingback: 13 Useful Code Snippets for WordPress Development | WebsGeek
Pingback: 13 Useful Code Snippets for WordPress Development « HUE Designer
Pingback: 20+ WordPress Codes You Might Need On Your Next Project | Web Design Philippines | MikeWagan.net
Pingback: 50 Ultimate Tutorials To Make You A Power Wordpress User | stylishwebdesigner
Pingback: 136 Massive Wordpress Tutorial Collection | WebCoreStudio
Pingback: 135 link cung c?p th? thu?t wordpress hot nh?t | T?p Chí SEO
Pingback: WordPress Themehacks » Die Tags in einem Dropdown Menu darstellen
Pingback: 135 webs/blog for wordpress tips |