Tuesday, August 21, 2012

How to create a dropdown menu of tags in wordpress

How to create a dropdown menu of tags in wordpress

Like wp_dropdown_categories() function which display the categories in a dropdown menu, there’s no built in function to display dropdown menu of tags in wordpress. But to display tags in a dropdown as well, Let’s use wp_dropdown_categories() and modify it in order to be able to display tags in a dropdown menu. Just paste the following code where you want the dropdown menu to be displayed. Here we can use our own taxonomy: Just modify the code on line 5 according to your needs.


<h2><?php _e('Posts by Tags'); ?></h2>
<form action="<?php bloginfo('url'); ?>/" method="get">
<div>
<?php
$select = wp_dropdown_categories('taxonomy=post_tag&show_option_none=Select tag&show_count=1&orderby=name&echo=0');
$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
echo $select;
?>
<noscript><div><input type="submit" value="View" /></div></noscript>
</div></form>

No comments:

Post a Comment

I just got my #domain @BigRock. Get upto 25% off with my personalized coupon link Get upto 25% off