~canonical-sysadmins/wordpress/3.9.x

« back to all changes in this revision

Viewing changes to wp-includes/category-template.php

  • Committer: Chris Jones
  • Date: 2010-01-19 13:17:33 UTC
  • Revision ID: cmsj@tenshu.net-20100119131733-rf31jv9k1v0xzo2h
[CJ] Import wordpress 2.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
344
344
        $defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0;
345
345
 
346
346
        $r = wp_parse_args( $args, $defaults );
 
347
 
 
348
        if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
 
349
                $r['pad_counts'] = true;
 
350
        }
 
351
 
347
352
        $r['include_last_update_time'] = $r['show_last_update'];
348
353
        extract( $r );
349
354
 
523
528
function wp_tag_cloud( $args = '' ) {
524
529
        $defaults = array(
525
530
                'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
526
 
                'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',
 
531
                'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
527
532
                'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true
528
533
        );
529
534
        $args = wp_parse_args( $args, $defaults );
566
571
}
567
572
 
568
573
/**
 
574
 * Default topic count scaling for tag links
 
575
 *
 
576
 * @param integer $count number of posts with that tag
 
577
 * @return integer scaled count
 
578
 */
 
579
function default_topic_count_scale( $count ) {
 
580
        return round(log10($count + 1) * 100);
 
581
}
 
582
 
 
583
 
 
584
/**
569
585
 * Generates a tag cloud (heatmap) from provided data.
570
586
 *
571
587
 * The text size is set by the 'smallest' and 'largest' arguments, which will
575
591
 * 'format' argument will format the tags in a UL HTML list. The array value for
576
592
 * the 'format' argument will return in PHP array type format.
577
593
 *
578
 
 * The 'tag_cloud_sort' filter allows you to override the sorting done
579
 
 * by the 'orderby' argument; passed to the filter: $tags array and $args array.
 
594
 * The 'tag_cloud_sort' filter allows you to override the sorting.
 
595
 * Passed to the filter: $tags array and $args array, has to return the $tags array
 
596
 * after sorting it.
580
597
 *
581
598
 * The 'orderby' argument will accept 'name' or 'count' and defaults to 'name'.
582
599
 * The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC' or
599
616
        global $wp_rewrite;
600
617
        $defaults = array(
601
618
                'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0,
602
 
                'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',
 
619
                'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
603
620
                'topic_count_text_callback' => 'default_topic_count_text',
604
 
                'filter' => 1,
 
621
                'topic_count_scale_callback' => 'default_topic_count_scale', 'filter' => 1,
605
622
        );
606
623
 
607
624
        if ( !isset( $args['topic_count_text_callback'] ) && isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) {
608
625
                $body = 'return sprintf (
609
 
                        _n('.var_export($args['single_text'], true).', '.var_export($args['multiple_text'], true).', $count),
 
626
                        _n(' . var_export($args['single_text'], true) . ', ' . var_export($args['multiple_text'], true) . ', $count),
610
627
                        number_format_i18n( $count ));';
611
628
                $args['topic_count_text_callback'] = create_function('$count', $body);
612
629
        }
613
630
 
614
631
        $args = wp_parse_args( $args, $defaults );
615
 
 
616
632
        extract( $args );
617
633
 
618
634
        if ( empty( $tags ) )
619
635
                return;
620
636
 
621
 
        // SQL cannot save you; this is a second (potentially different) sort on a subset of data.
622
 
        if ( 'name' == $orderby )
623
 
                uasort( $tags, create_function('$a, $b', 'return strnatcasecmp($a->name, $b->name);') );
624
 
        else
625
 
                uasort( $tags, create_function('$a, $b', 'return ($a->count > $b->count);') );
626
 
 
627
 
        $tags = apply_filters( 'tag_cloud_sort', $tags, $args );
628
 
 
629
 
        if ( 'DESC' == $order )
630
 
                $tags = array_reverse( $tags, true );
631
 
        elseif ( 'RAND' == $order ) {
632
 
                $keys = (array) array_rand( $tags, count( $tags ) );
633
 
                $temp = array();
634
 
                foreach ( $keys as $key )
635
 
                        $temp[$key] = $tags[$key];
636
 
 
637
 
                $tags = $temp;
638
 
                $temp = null;
639
 
                unset( $temp );
 
637
        $tags_sorted = apply_filters( 'tag_cloud_sort', $tags, $args );
 
638
        if ( $tags_sorted != $tags  ) { // the tags have been sorted by a plugin
 
639
                $tags = $tags_sorted;
 
640
                unset($tags_sorted);
 
641
        } else {
 
642
                if ( 'RAND' == $order ) {
 
643
                        shuffle($tags);
 
644
                } else {
 
645
                        // SQL cannot save you; this is a second (potentially different) sort on a subset of data.
 
646
                        if ( 'name' == $orderby )
 
647
                                uasort( $tags, create_function('$a, $b', 'return strnatcasecmp($a->name, $b->name);') );
 
648
                        else
 
649
                                uasort( $tags, create_function('$a, $b', 'return ($a->count > $b->count);') );
 
650
 
 
651
                        if ( 'DESC' == $order )
 
652
                                $tags = array_reverse( $tags, true );
 
653
                }
640
654
        }
641
655
 
642
656
        if ( $number > 0 )
643
657
                $tags = array_slice($tags, 0, $number);
644
658
 
645
659
        $counts = array();
646
 
        foreach ( (array) $tags as $key => $tag )
647
 
                $counts[ $key ] = $tag->count;
 
660
        $real_counts = array(); // For the alt tag
 
661
        foreach ( (array) $tags as $key => $tag ) {
 
662
                $real_counts[ $key ] = $tag->count;
 
663
                $counts[ $key ] = $topic_count_scale_callback($tag->count);
 
664
        }
648
665
 
649
666
        $min_count = min( $counts );
650
667
        $spread = max( $counts ) - $min_count;
657
674
 
658
675
        $a = array();
659
676
 
660
 
        $rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? ' rel="tag"' : '';
661
 
 
662
677
        foreach ( $tags as $key => $tag ) {
663
678
                $count = $counts[ $key ];
 
679
                $real_count = $real_counts[ $key ];
664
680
                $tag_link = '#' != $tag->link ? esc_url( $tag->link ) : '#';
665
681
                $tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key;
666
682
                $tag_name = $tags[ $key ]->name;
667
 
                $a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . esc_attr( $topic_count_text_callback( $count ) ) . "'$rel style='font-size: " .
 
683
                $a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . esc_attr( $topic_count_text_callback( $real_count ) ) . "' style='font-size: " .
668
684
                        ( $smallest + ( ( $count - $min_count ) * $font_step ) )
669
685
                        . "$unit;'>$tag_name</a>";
670
686
        }
679
695
                $return .= "</li>\n</ul>\n";
680
696
                break;
681
697
        default :
682
 
                $return = join( "\n", $a );
 
698
                $return = join( $separator, $a );
683
699
                break;
684
700
        endswitch;
685
701
 
851
867
 
852
868
        $id = (int) $id;
853
869
 
854
 
        if ( ! $id && ! in_the_loop() )
855
 
                return false; // in-the-loop function
856
 
 
857
 
        if ( !$id )
858
 
                $id = (int) $post->ID;
 
870
        if ( !$id ) {
 
871
                if ( !$post->ID )
 
872
                        return false;
 
873
                else
 
874
                        $id = (int) $post->ID;
 
875
        }
859
876
 
860
877
        $terms = get_object_term_cache( $id, $taxonomy );
861
878
        if ( false === $terms )
868
885
}
869
886
 
870
887
/**
871
 
 * Retrieve terms as a list with specified format.
 
888
 * Retrieve a post's terms as a list with specified format.
872
889
 *
873
890
 * @since 2.5.0
874
891
 *
875
 
 * @param int $id Term ID.
 
892
 * @param int $id Post ID.
876
893
 * @param string $taxonomy Taxonomy name.
877
894
 * @param string $before Optional. Before list.
878
895
 * @param string $sep Optional. Separate items using this.
912
929
 * @param string $after Optional. After list.
913
930
 * @return null|bool False on WordPress error. Returns null when displaying.
914
931
 */
915
 
function the_terms( $id, $taxonomy, $before = '', $sep = '', $after = '' ) {
916
 
        $return = get_the_term_list( $id, $taxonomy, $before, $sep, $after );
917
 
        if ( is_wp_error( $return ) )
 
932
function the_terms( $id, $taxonomy, $before = '', $sep = ', ', $after = '' ) {
 
933
        $term_list = get_the_term_list( $id, $taxonomy, $before, $sep, $after );
 
934
 
 
935
        if ( is_wp_error( $term_list ) )
918
936
                return false;
919
 
        else
920
 
                echo $return;
 
937
 
 
938
        echo apply_filters('the_terms', $term_list, $taxonomy, $before, $sep, $after);
921
939
}
922
940
 
923
941
/**