Want more features on Pastebin? Sign Up, it's FREE!
Guest

wp_tag_cloud

By: a guest on Apr 7th, 2012  |  syntax: None  |  size: 1.15 KB  |  views: 33  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function wp_tag_cloud( $args = '' ) {
  2.         $defaults = array(
  3.                 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
  4.                 'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
  5.                 'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true
  6.         );
  7.         $args = wp_parse_args( $args, $defaults );
  8.  
  9.         $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags
  10.  
  11.         if ( empty( $tags ) || is_wp_error( $tags ) )
  12.                 return;
  13.  
  14.         foreach ( $tags as $key => $tag ) {
  15.                 if ( 'edit' == $args['link'] )
  16.                         $link = get_edit_tag_link( $tag->term_id, $tag->taxonomy );
  17.                 else
  18.                         $link = get_term_link( intval($tag->term_id), $tag->taxonomy );
  19.                 if ( is_wp_error( $link ) )
  20.                         return false;
  21.  
  22.                 $tags[ $key ]->link = $link;
  23.                 $tags[ $key ]->id = $tag->term_id;
  24.         }
  25.  
  26.         $return = wp_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args
  27.  
  28.         $return = apply_filters( 'wp_tag_cloud', $return, $args );
  29.  
  30.         if ( 'array' == $args['format'] || empty($args['echo']) )
  31.                 return $return;
  32.  
  33.         echo $return;
  34. }
clone this paste RAW Paste Data