/ Published in: PHP
From Web Design Ledger "13 Useful Code Snippets for WordPress Development"
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php function dropdown_tag_cloud( $args = '' ) { '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 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; 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45, 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC' ); $args = wp_parse_args( $args, $defaults ); if ( !$tags ) return; $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; } 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 ) else if ( 'DESC' == $order ) foreach ( $counts as $tag => $count ) { $tag_id = $tag_ids[$tag]; $tag_link = clean_url($tag_links[$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 .= "</li>\n</ul>\n"; break; default : break; endswitch; return apply_filters( 'dropdown_generate_tag_cloud', $return, $tags, $args ); } ?> /* "Now, to finalize your dropdown menu you have to open the theme file where you want the list to be displayed (i.e. sidebar.php) and insert 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> */
URL: http://webdesignledger.com/tips/13-useful-code-snippets-for-wordpress-development