154
162
function get_the_category_list( $separator = '', $parents='', $post_id = false ) {
155
163
global $wp_rewrite;
156
if ( ! is_object_in_taxonomy( get_post_type( $post_id ), 'category' ) )
164
if ( ! is_object_in_taxonomy( get_post_type( $post_id ), 'category' ) ) {
165
/** This filter is documented in wp-includes/category-template.php */
157
166
return apply_filters( 'the_category', '', $separator, $parents );
159
169
$categories = get_the_category( $post_id );
160
if ( empty( $categories ) )
170
if ( empty( $categories ) ) {
171
/** This filter is documented in wp-includes/category-template.php */
161
172
return apply_filters( 'the_category', __( 'Uncategorized' ), $separator, $parents );
163
175
$rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="category"';
349
387
if ( ! empty( $categories ) ) {
351
389
if ( $show_option_all ) {
391
/** This filter is documented in wp-includes/category-template.php */
352
392
$show_option_all = apply_filters( 'list_cats', $show_option_all );
353
393
$selected = ( '0' === strval($r['selected']) ) ? " selected='selected'" : '';
354
394
$output .= "\t<option value='0'$selected>$show_option_all</option>\n";
357
397
if ( $show_option_none ) {
399
/** This filter is documented in wp-includes/category-template.php */
358
400
$show_option_none = apply_filters( 'list_cats', $show_option_none );
359
401
$selected = ( '-1' === strval($r['selected']) ) ? " selected='selected'" : '';
360
402
$output .= "\t<option value='-1'$selected>$show_option_none</option>\n";
507
565
* The 'number' argument is how many tags to return. By default, the limit will
508
566
* be to return the top 45 tags in the tag cloud list.
510
* The 'topic_count_text_callback' argument is a function, which, given the count
511
* of the posts with that tag, returns a text for the tooltip of the tag link.
568
* The 'topic_count_text' argument is a nooped plural from _n_noop() to generate the
569
* text for the tooltip of the tag link.
571
* The 'topic_count_text_callback' argument is a function, which given the count
572
* of the posts with that tag returns a text for the tooltip of the tag link.
574
* The 'post_type' argument is used only when 'link' is set to 'edit'. It determines the post_type
575
* passed to edit.php for the popular tags edit links.
513
577
* The 'exclude' and 'include' arguments are used for the {@link get_tags()}
514
578
* function. Only one should be used, because only one will be used and the
523
587
$defaults = array(
524
588
'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
525
589
'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
526
'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true
590
'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'post_type' => '', 'echo' => true
528
592
$args = wp_parse_args( $args, $defaults );
595
657
* The 'number' argument is how many tags to return. By default, the limit will
596
658
* be to return the entire tag cloud list.
660
* The 'topic_count_text' argument is a nooped plural from _n_noop() to generate the
661
* text for the tooltip of the tag link.
598
663
* The 'topic_count_text_callback' argument is a function, which given the count
599
* of the posts with that tag returns a text for the tooltip of the tag link.
664
* of the posts with that tag returns a text for the tooltip of the tag link.
601
666
* @todo Complete functionality.
604
669
* @param array $tags List of tags.
605
670
* @param string|array $args Optional, override default arguments.
671
* @return string|array Tag cloud as a string or an array, depending on 'format' argument.
608
673
function wp_generate_tag_cloud( $tags, $args = '' ) {
609
674
$defaults = array(
610
675
'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0,
611
676
'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
612
'topic_count_text_callback' => 'default_topic_count_text',
677
'topic_count_text' => null, 'topic_count_text_callback' => null,
613
678
'topic_count_scale_callback' => 'default_topic_count_scale', 'filter' => 1,
616
if ( !isset( $args['topic_count_text_callback'] ) && isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) {
617
$body = 'return sprintf (
618
_n(' . var_export($args['single_text'], true) . ', ' . var_export($args['multiple_text'], true) . ', $count),
619
number_format_i18n( $count ));';
620
$args['topic_count_text_callback'] = create_function('$count', $body);
623
681
$args = wp_parse_args( $args, $defaults );
626
if ( empty( $tags ) )
682
extract( $args, EXTR_SKIP );
684
$return = ( 'array' === $format ) ? array() : '';
686
if ( empty( $tags ) ) {
690
// Juggle topic count tooltips:
691
if ( isset( $args['topic_count_text'] ) ) {
692
// First look for nooped plural support via topic_count_text.
693
$translate_nooped_plural = $args['topic_count_text'];
694
} elseif ( ! empty( $args['topic_count_text_callback'] ) ) {
695
// Look for the alternative callback style. Ignore the previous default.
696
if ( $args['topic_count_text_callback'] === 'default_topic_count_text' ) {
697
$translate_nooped_plural = _n_noop( '%s topic', '%s topics' );
699
$translate_nooped_plural = false;
701
} elseif ( isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) {
702
// If no callback exists, look for the old-style single_text and multiple_text arguments.
703
$translate_nooped_plural = _n_noop( $args['single_text'], $args['multiple_text'] );
705
// This is the default for when no callback, plural, or argument is passed in.
706
$translate_nooped_plural = _n_noop( '%s topic', '%s topics' );
710
* Filter how the items in a tag cloud are sorted.
714
* @param array $tags Ordered array of terms.
715
* @param array $args An array of tag cloud arguments.
629
717
$tags_sorted = apply_filters( 'tag_cloud_sort', $tags, $args );
630
if ( $tags_sorted != $tags ) { // the tags have been sorted by a plugin
718
if ( empty( $tags_sorted ) ) {
722
if ( $tags_sorted !== $tags ) {
631
723
$tags = $tags_sorted;
724
unset( $tags_sorted );
634
if ( 'RAND' == $order ) {
726
if ( 'RAND' === $order ) {
637
729
// SQL cannot save you; this is a second (potentially different) sort on a subset of data.
638
if ( 'name' == $orderby )
730
if ( 'name' === $orderby ) {
639
731
uasort( $tags, '_wp_object_name_sort_cb' );
641
733
uasort( $tags, '_wp_object_count_sort_cb' );
643
if ( 'DESC' == $order )
736
if ( 'DESC' === $order ) {
644
737
$tags = array_reverse( $tags, true );
672
766
$tag_link = '#' != $tag->link ? esc_url( $tag->link ) : '#';
673
767
$tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key;
674
768
$tag_name = $tags[ $key ]->name;
675
$a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . esc_attr( call_user_func( $topic_count_text_callback, $real_count, $tag, $args ) ) . "' style='font-size: " .
770
if ( $translate_nooped_plural ) {
771
$title_attribute = sprintf( translate_nooped_plural( $translate_nooped_plural, $real_count ), number_format_i18n( $real_count ) );
773
$title_attribute = call_user_func( $topic_count_text_callback, $real_count, $tag, $args );
776
$a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . esc_attr( $title_attribute ) . "' style='font-size: " .
676
777
str_replace( ',', '.', ( $smallest + ( ( $count - $min_count ) * $font_step ) ) )
677
778
. "$unit;'>$tag_name</a>";
843
962
$cat_name = esc_attr( $category->name );
964
/** This filter is documented in wp-includes/category-template.php */
844
965
$cat_name = apply_filters( 'list_cats', $cat_name, $category );
845
967
$link = '<a href="' . esc_url( get_term_link($category) ) . '" ';
846
if ( $use_desc_for_title == 0 || empty($category->description) )
968
if ( $use_desc_for_title == 0 || empty($category->description) ) {
847
969
$link .= 'title="' . esc_attr( sprintf(__( 'View all posts filed under %s' ), $cat_name) ) . '"';
972
* Filter the category description for display.
976
* @param string $description Category description.
977
* @param object $category Category object.
849
979
$link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"';
851
983
$link .= $cat_name . '</a>';
958
1090
function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
959
1091
$pad = str_repeat(' ', $depth * 3);
961
$cat_name = apply_filters('list_cats', $category->name, $category);
1093
/** This filter is documented in wp-includes/category-template.php */
1094
$cat_name = apply_filters( 'list_cats', $category->name, $category );
962
1096
$output .= "\t<option class=\"level-$depth\" value=\"".$category->term_id."\"";
963
1097
if ( $category->term_id == $args['selected'] )
964
1098
$output .= ' selected="selected"';
966
1100
$output .= $pad.$cat_name;
967
1101
if ( $args['show_count'] )
968
$output .= ' ('. $category->count .')';
1102
$output .= ' ('. number_format_i18n( $category->count ) .')';
969
1103
$output .= "</option>\n";
1021
1163
* @return string|bool|WP_Error A list of tags on success, false or WP_Error on failure.
1023
1165
function get_the_tag_list( $before = '', $sep = '', $after = '', $id = 0 ) {
1168
* Filter the tags list for a given post.
1172
* @param string $tag_list List of tags.
1173
* @param string $before String to use before tags.
1174
* @param string $sep String to use between the tags.
1175
* @param string $after String to use after tags.
1176
* @param int $id Post ID.
1024
1178
return apply_filters( 'the_tags', get_the_term_list( $id, 'post_tag', $before, $sep, $after ), $before, $sep, $after, $id );
1150
1323
if ( is_wp_error( $term_list ) )
1153
echo apply_filters('the_terms', $term_list, $taxonomy, $before, $sep, $after);
1327
* Filter the list of terms to display.
1331
* @param array $term_list List of terms to display.
1332
* @param string $taxonomy The taxonomy name.
1333
* @param string $before String to use before the terms.
1334
* @param string $sep String to use between the terms.
1335
* @param string $after String to use after the terms.
1337
echo apply_filters( 'the_terms', $term_list, $taxonomy, $before, $sep, $after );