8, 'largest' => 22, 'unit' => 'pt', 'number' => 45, 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC', 'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => OCI_DEFAULT_TAG_TAXONOMY, 'url' => OCI_DEFAULT_URL, 'type' => 'all', 'hide_empty' => false ); $args = wp_parse_args( $args, $defaults ); // woah. $args['taxonomy'] can be an array of tax's. hmmm $tags = oci_get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags if ( empty( $tags ) ) return; foreach ( $tags as $key => $tag ) { if ( 'edit' == $args['link'] ) $link = oci_get_edit_tag_link( $tag->term_id, $args['taxonomy'] ); else $link = oci_get_term_link( intval($tag->term_id), $args['taxonomy'], $args['url'], $args['type'] ); if ( is_wp_error( $link ) ) return false; $tags[ $key ]->link = $link; $tags[ $key ]->id = $tag->term_id; } $return = oci_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args $return = apply_filters( 'oci_tag_cloud', $return, $args ); return $return; } /** * Generates a tag cloud (heatmap) from provided data. * * The text size is set by the 'smallest' and 'largest' arguments, which will * use the 'unit' argument value for the CSS text size unit. The 'format' * argument can be 'flat' (default), 'list', or 'array'. The flat value for the * 'format' argument will separate tags with spaces. The list value for the * 'format' argument will format the tags in a UL HTML list. The array value for * the 'format' argument will return in PHP array type format. * * The 'orderby' argument will accept 'name' or 'count' and defaults to 'name'. * The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC' or * 'RAND'. * * The 'number' argument is how many tags to return. By default, the limit will * be to return the entire tag cloud list. * * The 'topic_count_text_callback' argument is a function, which given the count * of the posts with that tag returns a text for the tooltip of the tag link. * * @todo Complete functionality. * @since 2.3.0 * * @param array $tags List of tags. * @param string|array $args Optional, override default arguments. * @return string */ function oci_generate_tag_cloud( $tags, $args = '' ) { global $wp_rewrite; $defaults = array( 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0, 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC', 'topic_count_text_callback' => 'default_topic_count_text', ); if ( !isset( $args['topic_count_text_callback'] ) && isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) { $body = 'return sprintf ( __ngettext('.var_export($args['single_text'], true).', '.var_export($args['multiple_text'], true).', $count), number_format_i18n( $count ));'; $args['topic_count_text_callback'] = create_function('$count', $body); } $args = wp_parse_args( $args, $defaults ); extract( $args ); if ( empty( $tags ) ) return; // SQL cannot save you; this is a second (potentially different) sort on a subset of data. if ( 'name' == $orderby ) uasort( $tags, create_function('$a, $b', 'return strnatcasecmp($a->name, $b->name);') ); else uasort( $tags, create_function('$a, $b', 'return ($a->count > $b->count);') ); if ( 'DESC' == $order ) $tags = array_reverse( $tags, true ); elseif ( 'RAND' == $order ) { $keys = array_rand( $tags, count( $tags ) ); foreach ( $keys as $key ) $temp[$key] = $tags[$key]; $tags = $temp; unset( $temp ); } if ( $number > 0 ) $tags = array_slice($tags, 0, $number); $counts = array(); foreach ( (array) $tags as $key => $tag ) $counts[ $key ] = $tag->count; $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; $a = array(); $rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? ' rel="tag"' : ''; foreach ( $tags as $key => $tag ) { $count = $counts[ $key ]; $tag_link = '#' != $tag->link ? clean_url( $tag->link ) : '#'; $tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key; $tag_name = $tags[ $key ]->name; $a[] = "$tag_name"; } switch ( $format ) : case 'array' : $return =& $a; break; case 'list' : $return = "