Ticket #6015: 6015.tags.diff
| File 6015.tags.diff, 3.4 KB (added by DD32, 5 years ago) |
|---|
-
wp-includes/category-template.php
350 350 if ( empty( $tags ) ) 351 351 return; 352 352 353 foreach ( $tags as $key => $tag ) { 354 $link = get_tag_link( $tag->term_id ); 355 if ( is_wp_error( $link ) ) 356 return false; 357 358 $tags[ $key ]->link = $link; 359 $tags[ $key ]->id = $tag->term_id; 360 } 361 353 362 $return = wp_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args 354 363 355 if ( is_wp_error( $return ) )356 return false;357 358 364 $return = apply_filters( 'wp_tag_cloud', $return, $args ); 359 365 360 366 if ( 'array' == $args['format'] ) … … 377 383 function wp_generate_tag_cloud( $tags, $args = '' ) { 378 384 global $wp_rewrite; 379 385 $defaults = array( 380 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45, 381 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC' 386 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 387 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC', 388 'single_text' => '%d topic', 'multiple_text' => '%d topics' 382 389 ); 383 390 $args = wp_parse_args( $args, $defaults ); 384 391 extract( $args ); 385 392 386 393 if ( empty( $tags ) ) 387 394 return; 388 $counts = $tag_links = array();389 foreach ( (array) $tags as $tag ) {390 $counts[$tag->name] = $tag->count;391 $tag_links[$tag->name] = get_tag_link( $tag->term_id );392 if ( is_wp_error( $tag_links[$tag->name] ) )393 return $tag_links[$tag->name];394 $tag_ids[$tag->name] = $tag->term_id;395 }396 395 396 $counts = array(); 397 foreach ( (array) $tags as $key => $tag ) 398 $counts[ $key ] = $tag->count; 399 397 400 $min_count = min( $counts ); 398 401 $spread = max( $counts ) - $min_count; 399 402 if ( $spread <= 0 ) … … 405 408 406 409 // SQL cannot save you; this is a second (potentially different) sort on a subset of data. 407 410 if ( 'name' == $orderby ) 408 u ksort( $counts, 'strnatcasecmp');411 uasort( $tags, create_function('$a, $b', 'return strnatcasecmp($a->name, $b->name);') ); 409 412 else 410 asort( $counts);413 uasort( $tags, create_function('$a, $b', 'return ($a->count < $b->count);') ); 411 414 412 415 if ( 'DESC' == $order ) 413 $ counts = array_reverse( $counts, true );416 $tags = array_reverse( $tags, true ); 414 417 elseif ( 'RAND' == $order ) { 415 $keys = array_rand( $ counts, count( $counts ) );418 $keys = array_rand( $tags, count( $tags ) ); 416 419 foreach ( $keys as $key ) 417 $temp[$key] = $ counts[$key];418 $ counts = $temp;420 $temp[$key] = $tags[$key]; 421 $tags = $temp; 419 422 unset( $temp ); 420 423 } 421 424 … … 423 426 424 427 $rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? ' rel="tag"' : ''; 425 428 426 foreach ( $counts as $tag => $count ) { 427 $tag_id = $tag_ids[$tag]; 428 $tag_link = clean_url($tag_links[$tag]); 429 $a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . attribute_escape( sprintf( __ngettext('%d topic','%d topics',$count), $count ) ) . "'$rel style='font-size: " . 429 foreach ( $tags as $key => $tag ) { 430 $count = $counts[ $key ]; 431 $tag_link = clean_url( $tag->link ); 432 $tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key; 433 $tag_name = $tags[ $key ]->name; 434 $a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . attribute_escape( sprintf( __ngettext( $single_text, $multiple_text, $count ), $count ) ) . "'$rel style='font-size: " . 430 435 ( $smallest + ( ( $count - $min_count ) * $font_step ) ) 431 . "$unit;'>$tag </a>";436 . "$unit;'>$tag_name</a>"; 432 437 } 433 438 434 439 switch ( $format ) :