Advertise on Site! You can Advertise on our site. Find out More

Display wordpress Tags In A Dropdown Menu without plugin

If you want to display the tags in drop down menu then use following code in functions.php file.


<?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 );
}
?>

In footer or sidebar file or where you want to display the tags in dropdown use 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>

  • Pingback: Bonsai 4 U Ni | Bonsai Cuttings

  • Pingback: Bonsai Forest | Bonsai Cuttings

  • http://college-forphysicaltherapy.blogspot.com/ Dudley Codell

    Awesome post. I so good to see someone taking the time to share this information

  • http://uautocity.info Lara Ordones

    Of course, what a great site and informative posts, I will add backlink – bookmark this site? Regards, Reader

  • http://uautocity.info Joaquin Pov

    Hello, this is my first time i visit here. I found so many interesting in your blog especially on how to determine the topic. keep up the good work.

  • http://ecommerce-web.info Anibal Mehr

    I’ve been checking your blog for a while now, seems like everyday I learn something new :-) Thanks

  • http://www.weightloss2ublog.com Myles Glaue

    Awesome post. I so good to see someone taking the time to share this information

  • http://ecommerce-web.info Marcos Victory

    I was just having a conversation over this I am glad I came across this it cleared some of the questions I had.

  • http://heart-diseases-symptoms.info Talisha Tanen

    I’ve just started off a blog, the knowledge you give on this site has aided me extremely. Thank you for all your time & work.

  • http://uu-skin-care.blogspot.com/ Laura Lough

    Of course, what a great site and informative posts, I will add backlink – bookmark this site? Regards, Reader

  • http://www.weightloss2ublog.com Marcos Victory

    Intriguing post. I have been searching for some good resources for solar panels and discovered your blog. Planning to bookmark this one!

  • http://ecommerce-web.info Magaret Likar

    I REALLY liked your post and blog! It took me a minute bit to find your site…but I bookmarked it. Would you mind if I posted a link back to your post?

  • http://menquitsmoking.com Taylor Pniewski

    Nice post! You truly have a wonderful way of writing which I find captivating! I will definitely be bookmarking you and returning to your blog. In fact, your post reminded me about a strange thing that happened to me the other day. I’ll tell you about that later…

  • http://ecommerce-web.info Dave Bertagna

    Great read. Thanks for the info!

  • http://detoxification-diets.info Joan Dafoe

    I’ve been checking your blog for a while now, seems like everyday I learn something new :-) Thanks