-
+ A0AFBAC4016F563B36ED4340E5B378F7E30F7EC246BE94D46B34B48CB8612D378EF988DFD1799A70236CEDC825D545212453E902A8BC035A6D49F0417886DF83mp-wp/wp-includes/category-template.php(0 . 0)(1 . 935)
74177 <?php
74178 /**
74179 * Category Template Tags and API.
74180 *
74181 * @package WordPress
74182 * @subpackage Template
74183 */
74184
74185 /**
74186 * Retrieve category children list separated before and after the term IDs.
74187 *
74188 * @since 1.2.0
74189 *
74190 * @param int $id Category ID to retrieve children.
74191 * @param string $before Optional. Prepend before category term ID.
74192 * @param string $after Optional, default is empty string. Append after category term ID.
74193 * @param array $visited Optional. Category Term IDs that have already been added.
74194 * @return string
74195 */
74196 function get_category_children( $id, $before = '/', $after = '', $visited = array() ) {
74197 if ( 0 == $id )
74198 return '';
74199
74200 $chain = '';
74201 /** TODO: consult hierarchy */
74202 $cat_ids = get_all_category_ids();
74203 foreach ( (array) $cat_ids as $cat_id ) {
74204 if ( $cat_id == $id )
74205 continue;
74206
74207 $category = get_category( $cat_id );
74208 if ( is_wp_error( $category ) )
74209 return $category;
74210 if ( $category->parent == $id && !in_array( $category->term_id, $visited ) ) {
74211 $visited[] = $category->term_id;
74212 $chain .= $before.$category->term_id.$after;
74213 $chain .= get_category_children( $category->term_id, $before, $after );
74214 }
74215 }
74216 return $chain;
74217 }
74218
74219 /**
74220 * Retrieve category link URL.
74221 *
74222 * @since 1.0.0
74223 * @uses apply_filters() Calls 'category_link' filter on category link and category ID.
74224 *
74225 * @param int $category_id Category ID.
74226 * @return string
74227 */
74228 function get_category_link( $category_id ) {
74229 global $wp_rewrite;
74230 $catlink = $wp_rewrite->get_category_permastruct();
74231
74232 if ( empty( $catlink ) ) {
74233 $file = get_option( 'home' ) . '/';
74234 $catlink = $file . '?cat=' . $category_id;
74235 } else {
74236 $category = &get_category( $category_id );
74237 if ( is_wp_error( $category ) )
74238 return $category;
74239 $category_nicename = $category->slug;
74240
74241 if ( $category->parent == $category_id ) // recursive recursion
74242 $category->parent = 0;
74243 elseif ($category->parent != 0 )
74244 $category_nicename = get_category_parents( $category->parent, false, '/', true ) . $category_nicename;
74245
74246 $catlink = str_replace( '%category%', $category_nicename, $catlink );
74247 $catlink = get_option( 'home' ) . user_trailingslashit( $catlink, 'category' );
74248 }
74249 return apply_filters( 'category_link', $catlink, $category_id );
74250 }
74251
74252 /**
74253 * Retrieve category parents with separator.
74254 *
74255 * @since 1.2.0
74256 *
74257 * @param int $id Category ID.
74258 * @param bool $link Optional, default is false. Whether to format with link.
74259 * @param string $separator Optional, default is '/'. How to separate categories.
74260 * @param bool $nicename Optional, default is false. Whether to use nice name for display.
74261 * @param array $visited Optional. Already linked to categories to prevent duplicates.
74262 * @return string
74263 */
74264 function get_category_parents( $id, $link = false, $separator = '/', $nicename = false, $visited = array() ) {
74265 $chain = '';
74266 $parent = &get_category( $id );
74267 if ( is_wp_error( $parent ) )
74268 return $parent;
74269
74270 if ( $nicename )
74271 $name = $parent->slug;
74272 else
74273 $name = $parent->cat_name;
74274
74275 if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) {
74276 $visited[] = $parent->parent;
74277 $chain .= get_category_parents( $parent->parent, $link, $separator, $nicename, $visited );
74278 }
74279
74280 if ( $link )
74281 $chain .= '<a href="' . get_category_link( $parent->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $parent->cat_name ) . '">'.$name.'</a>' . $separator;
74282 else
74283 $chain .= $name.$separator;
74284 return $chain;
74285 }
74286
74287 /**
74288 * Retrieve post categories.
74289 *
74290 * @since 0.71
74291 * @uses $post
74292 *
74293 * @param int $id Optional, default to current post ID. The post ID.
74294 * @return array
74295 */
74296 function get_the_category( $id = false ) {
74297 global $post;
74298
74299 $id = (int) $id;
74300 if ( !$id )
74301 $id = (int) $post->ID;
74302
74303 $categories = get_object_term_cache( $id, 'category' );
74304 if ( false === $categories ) {
74305 $categories = wp_get_object_terms( $id, 'category' );
74306 wp_cache_add($id, $categories, 'category_relationships');
74307 }
74308
74309 if ( !empty( $categories ) )
74310 usort( $categories, '_usort_terms_by_name' );
74311 else
74312 $categories = array();
74313
74314 foreach ( (array) array_keys( $categories ) as $key ) {
74315 _make_cat_compat( $categories[$key] );
74316 }
74317
74318 return $categories;
74319 }
74320
74321 /**
74322 * Sort categories by name.
74323 *
74324 * Used by usort() as a callback, should not be used directly. Can actually be
74325 * used to sort any term object.
74326 *
74327 * @since 2.3.0
74328 * @access private
74329 *
74330 * @param object $a
74331 * @param object $b
74332 * @return int
74333 */
74334 function _usort_terms_by_name( $a, $b ) {
74335 return strcmp( $a->name, $b->name );
74336 }
74337
74338 /**
74339 * Sort categories by ID.
74340 *
74341 * Used by usort() as a callback, should not be used directly. Can actually be
74342 * used to sort any term object.
74343 *
74344 * @since 2.3.0
74345 * @access private
74346 *
74347 * @param object $a
74348 * @param object $b
74349 * @return int
74350 */
74351 function _usort_terms_by_ID( $a, $b ) {
74352 if ( $a->term_id > $b->term_id )
74353 return 1;
74354 elseif ( $a->term_id < $b->term_id )
74355 return -1;
74356 else
74357 return 0;
74358 }
74359
74360 /**
74361 * Retrieve category name based on category ID.
74362 *
74363 * @since 0.71
74364 *
74365 * @param int $cat_ID Category ID.
74366 * @return string Category name.
74367 */
74368 function get_the_category_by_ID( $cat_ID ) {
74369 $cat_ID = (int) $cat_ID;
74370 $category = &get_category( $cat_ID );
74371 if ( is_wp_error( $category ) )
74372 return $category;
74373 return $category->name;
74374 }
74375
74376 /**
74377 * Retrieve category list in either HTML list or custom format.
74378 *
74379 * @since 1.5.1
74380 *
74381 * @param string $separator Optional, default is empty string. Separator for between the categories.
74382 * @param string $parents Optional. How to display the parents.
74383 * @param int $post_id Optional. Post ID to retrieve categories.
74384 * @return string
74385 */
74386 function get_the_category_list( $separator = '', $parents='', $post_id = false ) {
74387 global $wp_rewrite;
74388 $categories = get_the_category( $post_id );
74389 if ( empty( $categories ) )
74390 return apply_filters( 'the_category', __( 'Uncategorized' ), $separator, $parents );
74391
74392 $rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="category"';
74393
74394 $thelist = '';
74395 if ( '' == $separator ) {
74396 $thelist .= '<ul class="post-categories">';
74397 foreach ( $categories as $category ) {
74398 $thelist .= "\n\t<li>";
74399 switch ( strtolower( $parents ) ) {
74400 case 'multiple':
74401 if ( $category->parent )
74402 $thelist .= get_category_parents( $category->parent, true, $separator );
74403 $thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . $rel . '>' . $category->name.'</a></li>';
74404 break;
74405 case 'single':
74406 $thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . $rel . '>';
74407 if ( $category->parent )
74408 $thelist .= get_category_parents( $category->parent, false, $separator );
74409 $thelist .= $category->name.'</a></li>';
74410 break;
74411 case '':
74412 default:
74413 $thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . $rel . '>' . $category->cat_name.'</a></li>';
74414 }
74415 }
74416 $thelist .= '</ul>';
74417 } else {
74418 $i = 0;
74419 foreach ( $categories as $category ) {
74420 if ( 0 < $i )
74421 $thelist .= $separator . ' ';
74422 switch ( strtolower( $parents ) ) {
74423 case 'multiple':
74424 if ( $category->parent )
74425 $thelist .= get_category_parents( $category->parent, true, $separator );
74426 $thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . $rel . '>' . $category->cat_name.'</a>';
74427 break;
74428 case 'single':
74429 $thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . $rel . '>';
74430 if ( $category->parent )
74431 $thelist .= get_category_parents( $category->parent, false, $separator );
74432 $thelist .= "$category->cat_name</a>";
74433 break;
74434 case '':
74435 default:
74436 $thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . $rel . '>' . $category->name.'</a>';
74437 }
74438 ++$i;
74439 }
74440 }
74441 return apply_filters( 'the_category', $thelist, $separator, $parents );
74442 }
74443
74444
74445 /**
74446 * Check if the current post in within any of the given categories.
74447 *
74448 * The given categories are checked against the post's categories' term_ids, names and slugs.
74449 * Categories given as integers will only be checked against the post's categories' term_ids.
74450 *
74451 * Prior to v2.5 of WordPress, category names were not supported.
74452 * Prior to v2.7, category slugs were not supported.
74453 * Prior to v2.7, only one category could be compared: in_category( $single_category ).
74454 * Prior to v2.7, this function could only be used in the WordPress Loop.
74455 * As of 2.7, the function can be used anywhere if it is provided a post ID or post object.
74456 *
74457 * @since 1.2.0
74458 *
74459 * @uses is_object_in_term()
74460 *
74461 * @param int|string|array $category. Category ID, name or slug, or array of said.
74462 * @param int|post object Optional. Post to check instead of the current post. @since 2.7.0
74463 * @return bool True if the current post is in any of the given categories.
74464 */
74465 function in_category( $category, $_post = null ) {
74466 if ( empty( $category ) )
74467 return false;
74468
74469 if ( $_post ) {
74470 $_post = get_post( $_post );
74471 } else {
74472 $_post =& $GLOBALS['post'];
74473 }
74474
74475 if ( !$_post )
74476 return false;
74477
74478 $r = is_object_in_term( $_post->ID, 'category', $category );
74479 if ( is_wp_error( $r ) )
74480 return false;
74481 return $r;
74482 }
74483
74484 /**
74485 * Display the category list for the post.
74486 *
74487 * @since 0.71
74488 *
74489 * @param string $separator Optional, default is empty string. Separator for between the categories.
74490 * @param string $parents Optional. How to display the parents.
74491 * @param int $post_id Optional. Post ID to retrieve categories.
74492 */
74493 function the_category( $separator = '', $parents='', $post_id = false ) {
74494 echo get_the_category_list( $separator, $parents, $post_id );
74495 }
74496
74497 /**
74498 * Retrieve category description.
74499 *
74500 * @since 1.0.0
74501 *
74502 * @param int $category Optional. Category ID. Will use global category ID by default.
74503 * @return string Category description, available.
74504 */
74505 function category_description( $category = 0 ) {
74506 global $cat;
74507 if ( !$category )
74508 $category = $cat;
74509
74510 return get_term_field( 'description', $category, 'category' );
74511 }
74512
74513 /**
74514 * Display or retrieve the HTML dropdown list of categories.
74515 *
74516 * The list of arguments is below:
74517 * 'show_option_all' (string) - Text to display for showing all categories.
74518 * 'show_option_none' (string) - Text to display for showing no categories.
74519 * 'orderby' (string) default is 'ID' - What column to use for ordering the
74520 * categories.
74521 * 'order' (string) default is 'ASC' - What direction to order categories.
74522 * 'show_last_update' (bool|int) default is 0 - See {@link get_categories()}
74523 * 'show_count' (bool|int) default is 0 - Whether to show how many posts are
74524 * in the category.
74525 * 'hide_empty' (bool|int) default is 1 - Whether to hide categories that
74526 * don't have any posts attached to them.
74527 * 'child_of' (int) default is 0 - See {@link get_categories()}.
74528 * 'exclude' (string) - See {@link get_categories()}.
74529 * 'echo' (bool|int) default is 1 - Whether to display or retrieve content.
74530 * 'depth' (int) - The max depth.
74531 * 'tab_index' (int) - Tab index for select element.
74532 * 'name' (string) - The name attribute value for selected element.
74533 * 'class' (string) - The class attribute value for selected element.
74534 * 'selected' (int) - Which category ID is selected.
74535 *
74536 * The 'hierarchical' argument, which is disabled by default, will override the
74537 * depth argument, unless it is true. When the argument is false, it will
74538 * display all of the categories. When it is enabled it will use the value in
74539 * the 'depth' argument.
74540 *
74541 * @since 2.1.0
74542 *
74543 * @param string|array $args Optional. Override default arguments.
74544 * @return string HTML content only if 'echo' argument is 0.
74545 */
74546 function wp_dropdown_categories( $args = '' ) {
74547 $defaults = array(
74548 'show_option_all' => '', 'show_option_none' => '',
74549 'orderby' => 'ID', 'order' => 'ASC',
74550 'show_last_update' => 0, 'show_count' => 0,
74551 'hide_empty' => 1, 'child_of' => 0,
74552 'exclude' => '', 'echo' => 1,
74553 'selected' => 0, 'hierarchical' => 0,
74554 'name' => 'cat', 'class' => 'postform',
74555 'depth' => 0, 'tab_index' => 0
74556 );
74557
74558 $defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0;
74559
74560 $r = wp_parse_args( $args, $defaults );
74561 $r['include_last_update_time'] = $r['show_last_update'];
74562 extract( $r );
74563
74564 $tab_index_attribute = '';
74565 if ( (int) $tab_index > 0 )
74566 $tab_index_attribute = " tabindex=\"$tab_index\"";
74567
74568 $categories = get_categories( $r );
74569
74570 $output = '';
74571 if ( ! empty( $categories ) ) {
74572 $output = "<select name='$name' id='$name' class='$class' $tab_index_attribute>\n";
74573
74574 if ( $show_option_all ) {
74575 $show_option_all = apply_filters( 'list_cats', $show_option_all );
74576 $output .= "\t<option value='0'>$show_option_all</option>\n";
74577 }
74578
74579 if ( $show_option_none ) {
74580 $show_option_none = apply_filters( 'list_cats', $show_option_none );
74581 $output .= "\t<option value='-1'>$show_option_none</option>\n";
74582 }
74583
74584 if ( $hierarchical )
74585 $depth = $r['depth']; // Walk the full depth.
74586 else
74587 $depth = -1; // Flat.
74588
74589 $output .= walk_category_dropdown_tree( $categories, $depth, $r );
74590 $output .= "</select>\n";
74591 }
74592
74593 $output = apply_filters( 'wp_dropdown_cats', $output );
74594
74595 if ( $echo )
74596 echo $output;
74597
74598 return $output;
74599 }
74600
74601 /**
74602 * Display or retrieve the HTML list of categories.
74603 *
74604 * The list of arguments is below:
74605 * 'show_option_all' (string) - Text to display for showing all categories.
74606 * 'orderby' (string) default is 'ID' - What column to use for ordering the
74607 * categories.
74608 * 'order' (string) default is 'ASC' - What direction to order categories.
74609 * 'show_last_update' (bool|int) default is 0 - See {@link
74610 * walk_category_dropdown_tree()}
74611 * 'show_count' (bool|int) default is 0 - Whether to show how many posts are
74612 * in the category.
74613 * 'hide_empty' (bool|int) default is 1 - Whether to hide categories that
74614 * don't have any posts attached to them.
74615 * 'use_desc_for_title' (bool|int) default is 1 - Whether to use the
74616 * description instead of the category title.
74617 * 'feed' - See {@link get_categories()}.
74618 * 'feed_type' - See {@link get_categories()}.
74619 * 'feed_image' - See {@link get_categories()}.
74620 * 'child_of' (int) default is 0 - See {@link get_categories()}.
74621 * 'exclude' (string) - See {@link get_categories()}.
74622 * 'echo' (bool|int) default is 1 - Whether to display or retrieve content.
74623 * 'current_category' (int) - See {@link get_categories()}.
74624 * 'hierarchical' (bool) - See {@link get_categories()}.
74625 * 'title_li' (string) - See {@link get_categories()}.
74626 * 'depth' (int) - The max depth.
74627 *
74628 * @since 2.1.0
74629 *
74630 * @param string|array $args Optional. Override default arguments.
74631 * @return string HTML content only if 'echo' argument is 0.
74632 */
74633 function wp_list_categories( $args = '' ) {
74634 $defaults = array(
74635 'show_option_all' => '', 'orderby' => 'name',
74636 'order' => 'ASC', 'show_last_update' => 0,
74637 'style' => 'list', 'show_count' => 0,
74638 'hide_empty' => 1, 'use_desc_for_title' => 1,
74639 'child_of' => 0, 'feed' => '', 'feed_type' => '',
74640 'feed_image' => '', 'exclude' => '', 'current_category' => 0,
74641 'hierarchical' => true, 'title_li' => __( 'Categories' ),
74642 'echo' => 1, 'depth' => 0
74643 );
74644
74645 $r = wp_parse_args( $args, $defaults );
74646
74647 if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
74648 $r['pad_counts'] = true;
74649 }
74650
74651 if ( isset( $r['show_date'] ) ) {
74652 $r['include_last_update_time'] = $r['show_date'];
74653 }
74654
74655 extract( $r );
74656
74657 $categories = get_categories( $r );
74658
74659 $output = '';
74660 if ( $title_li && 'list' == $style )
74661 $output = '<li class="categories">' . $r['title_li'] . '<ul>';
74662
74663 if ( empty( $categories ) ) {
74664 if ( 'list' == $style )
74665 $output .= '<li>' . __( "No categories" ) . '</li>';
74666 else
74667 $output .= __( "No categories" );
74668 } else {
74669 global $wp_query;
74670
74671 if( !empty( $show_option_all ) )
74672 if ( 'list' == $style )
74673 $output .= '<li><a href="' . get_bloginfo( 'url' ) . '">' . $show_option_all . '</a></li>';
74674 else
74675 $output .= '<a href="' . get_bloginfo( 'url' ) . '">' . $show_option_all . '</a>';
74676
74677 if ( empty( $r['current_category'] ) && is_category() )
74678 $r['current_category'] = $wp_query->get_queried_object_id();
74679
74680 if ( $hierarchical )
74681 $depth = $r['depth'];
74682 else
74683 $depth = -1; // Flat.
74684
74685 $output .= walk_category_tree( $categories, $depth, $r );
74686 }
74687
74688 if ( $title_li && 'list' == $style )
74689 $output .= '</ul></li>';
74690
74691 $output = apply_filters( 'wp_list_categories', $output );
74692
74693 if ( $echo )
74694 echo $output;
74695 else
74696 return $output;
74697 }
74698
74699 /**
74700 * Display tag cloud.
74701 *
74702 * The text size is set by the 'smallest' and 'largest' arguments, which will
74703 * use the 'unit' argument value for the CSS text size unit. The 'format'
74704 * argument can be 'flat' (default), 'list', or 'array'. The flat value for the
74705 * 'format' argument will separate tags with spaces. The list value for the
74706 * 'format' argument will format the tags in a UL HTML list. The array value for
74707 * the 'format' argument will return in PHP array type format.
74708 *
74709 * The 'orderby' argument will accept 'name' or 'count' and defaults to 'name'.
74710 * The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC'.
74711 *
74712 * The 'number' argument is how many tags to return. By default, the limit will
74713 * be to return the top 45 tags in the tag cloud list.
74714 *
74715 * The 'topic_count_text_callback' argument is a function, which, given the count
74716 * of the posts with that tag, returns a text for the tooltip of the tag link.
74717 * @see default_topic_count_text
74718 *
74719 * The 'exclude' and 'include' arguments are used for the {@link get_tags()}
74720 * function. Only one should be used, because only one will be used and the
74721 * other ignored, if they are both set.
74722 *
74723 * @since 2.3.0
74724 *
74725 * @param array|string $args Optional. Override default arguments.
74726 * @return array Generated tag cloud, only if no failures and 'array' is set for the 'format' argument.
74727 */
74728 function wp_tag_cloud( $args = '' ) {
74729 $defaults = array(
74730 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
74731 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',
74732 'exclude' => '', 'include' => '', 'link' => 'view'
74733 );
74734 $args = wp_parse_args( $args, $defaults );
74735
74736 $tags = get_tags( array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags
74737
74738 if ( empty( $tags ) )
74739 return;
74740
74741 foreach ( $tags as $key => $tag ) {
74742 if ( 'edit' == $args['link'] )
74743 $link = get_edit_tag_link( $tag->term_id );
74744 else
74745 $link = get_tag_link( $tag->term_id );
74746 if ( is_wp_error( $link ) )
74747 return false;
74748
74749 $tags[ $key ]->link = $link;
74750 $tags[ $key ]->id = $tag->term_id;
74751 }
74752
74753 $return = wp_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args
74754
74755 $return = apply_filters( 'wp_tag_cloud', $return, $args );
74756
74757 if ( 'array' == $args['format'] )
74758 return $return;
74759
74760 echo $return;
74761 }
74762
74763 /**
74764 * Default text for tooltip for tag links
74765 *
74766 * @param integer $count number of posts with that tag
74767 * @return string text for the tooltip of a tag link.
74768 */
74769 function default_topic_count_text( $count ) {
74770 return sprintf( __ngettext('%s topic', '%s topics', $count), number_format_i18n( $count ) );
74771 }
74772
74773 /**
74774 * Generates a tag cloud (heatmap) from provided data.
74775 *
74776 * The text size is set by the 'smallest' and 'largest' arguments, which will
74777 * use the 'unit' argument value for the CSS text size unit. The 'format'
74778 * argument can be 'flat' (default), 'list', or 'array'. The flat value for the
74779 * 'format' argument will separate tags with spaces. The list value for the
74780 * 'format' argument will format the tags in a UL HTML list. The array value for
74781 * the 'format' argument will return in PHP array type format.
74782 *
74783 * The 'orderby' argument will accept 'name' or 'count' and defaults to 'name'.
74784 * The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC' or
74785 * 'RAND'.
74786 *
74787 * The 'number' argument is how many tags to return. By default, the limit will
74788 * be to return the entire tag cloud list.
74789 *
74790 * The 'topic_count_text_callback' argument is a function, which given the count
74791 * of the posts with that tag returns a text for the tooltip of the tag link.
74792 * @see default_topic_count_text
74793 *
74794 *
74795 * @todo Complete functionality.
74796 * @since 2.3.0
74797 *
74798 * @param array $tags List of tags.
74799 * @param string|array $args Optional, override default arguments.
74800 * @return string
74801 */
74802 function wp_generate_tag_cloud( $tags, $args = '' ) {
74803 global $wp_rewrite;
74804 $defaults = array(
74805 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0,
74806 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',
74807 'topic_count_text_callback' => 'default_topic_count_text',
74808 );
74809
74810 if ( !isset( $args['topic_count_text_callback'] ) && isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) {
74811 $body = 'return sprintf (
74812 __ngettext('.var_export($args['single_text'], true).', '.var_export($args['multiple_text'], true).', $count),
74813 number_format_i18n( $count ));';
74814 $args['topic_count_text_callback'] = create_function('$count', $body);
74815 }
74816
74817 $args = wp_parse_args( $args, $defaults );
74818
74819 extract( $args );
74820
74821 if ( empty( $tags ) )
74822 return;
74823
74824 // SQL cannot save you; this is a second (potentially different) sort on a subset of data.
74825 if ( 'name' == $orderby )
74826 uasort( $tags, create_function('$a, $b', 'return strnatcasecmp($a->name, $b->name);') );
74827 else
74828 uasort( $tags, create_function('$a, $b', 'return ($a->count < $b->count);') );
74829
74830 if ( 'DESC' == $order )
74831 $tags = array_reverse( $tags, true );
74832 elseif ( 'RAND' == $order ) {
74833 $keys = array_rand( $tags, count( $tags ) );
74834 foreach ( $keys as $key )
74835 $temp[$key] = $tags[$key];
74836 $tags = $temp;
74837 unset( $temp );
74838 }
74839
74840 if ( $number > 0 )
74841 $tags = array_slice($tags, 0, $number);
74842
74843 $counts = array();
74844 foreach ( (array) $tags as $key => $tag )
74845 $counts[ $key ] = $tag->count;
74846
74847 $min_count = min( $counts );
74848 $spread = max( $counts ) - $min_count;
74849 if ( $spread <= 0 )
74850 $spread = 1;
74851 $font_spread = $largest - $smallest;
74852 if ( $font_spread < 0 )
74853 $font_spread = 1;
74854 $font_step = $font_spread / $spread;
74855
74856 $a = array();
74857
74858 $rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? ' rel="tag"' : '';
74859
74860 foreach ( $tags as $key => $tag ) {
74861 $count = $counts[ $key ];
74862 $tag_link = '#' != $tag->link ? clean_url( $tag->link ) : '#';
74863 $tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key;
74864 $tag_name = $tags[ $key ]->name;
74865 $a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . attribute_escape( $topic_count_text_callback( $count ) ) . "'$rel style='font-size: " .
74866 ( $smallest + ( ( $count - $min_count ) * $font_step ) )
74867 . "$unit;'>$tag_name</a>";
74868 }
74869
74870 switch ( $format ) :
74871 case 'array' :
74872 $return =& $a;
74873 break;
74874 case 'list' :
74875 $return = "<ul class='wp-tag-cloud'>\n\t<li>";
74876 $return .= join( "</li>\n\t<li>", $a );
74877 $return .= "</li>\n</ul>\n";
74878 break;
74879 default :
74880 $return = join( "\n", $a );
74881 break;
74882 endswitch;
74883
74884 return apply_filters( 'wp_generate_tag_cloud', $return, $tags, $args );
74885 }
74886
74887 //
74888 // Helper functions
74889 //
74890
74891 /**
74892 * Retrieve HTML list content for category list.
74893 *
74894 * @uses Walker_Category to create HTML list content.
74895 * @since 2.1.0
74896 * @see Walker_Category::walk() for parameters and return description.
74897 */
74898 function walk_category_tree() {
74899 $walker = new Walker_Category;
74900 $args = func_get_args();
74901 return call_user_func_array(array( &$walker, 'walk' ), $args );
74902 }
74903
74904 /**
74905 * Retrieve HTML dropdown (select) content for category list.
74906 *
74907 * @uses Walker_CategoryDropdown to create HTML dropdown content.
74908 * @since 2.1.0
74909 * @see Walker_CategoryDropdown::walk() for parameters and return description.
74910 */
74911 function walk_category_dropdown_tree() {
74912 $walker = new Walker_CategoryDropdown;
74913 $args = func_get_args();
74914 return call_user_func_array(array( &$walker, 'walk' ), $args );
74915 }
74916
74917 //
74918 // Tags
74919 //
74920
74921 /**
74922 * Retrieve the link to the tag.
74923 *
74924 * @since 2.3.0
74925 * @uses apply_filters() Calls 'tag_link' with tag link and tag ID as parameters.
74926 *
74927 * @param int $tag_id Tag (term) ID.
74928 * @return string
74929 */
74930 function get_tag_link( $tag_id ) {
74931 global $wp_rewrite;
74932 $taglink = $wp_rewrite->get_tag_permastruct();
74933
74934 $tag = &get_term( $tag_id, 'post_tag' );
74935 if ( is_wp_error( $tag ) )
74936 return $tag;
74937 $slug = $tag->slug;
74938
74939 if ( empty( $taglink ) ) {
74940 $file = get_option( 'home' ) . '/';
74941 $taglink = $file . '?tag=' . $slug;
74942 } else {
74943 $taglink = str_replace( '%tag%', $slug, $taglink );
74944 $taglink = get_option( 'home' ) . user_trailingslashit( $taglink, 'category' );
74945 }
74946 return apply_filters( 'tag_link', $taglink, $tag_id );
74947 }
74948
74949 /**
74950 * Retrieve the tags for a post.
74951 *
74952 * @since 2.3.0
74953 * @uses apply_filters() Calls 'get_the_tags' filter on the list of post tags.
74954 *
74955 * @param int $id Post ID.
74956 * @return array
74957 */
74958 function get_the_tags( $id = 0 ) {
74959 return apply_filters( 'get_the_tags', get_the_terms( $id, 'post_tag' ) );
74960 }
74961
74962 /**
74963 * Retrieve the tags for a post formatted as a string.
74964 *
74965 * @since 2.3.0
74966 * @uses apply_filters() Calls 'the_tags' filter on string list of tags.
74967 *
74968 * @param string $before Optional. Before tags.
74969 * @param string $sep Optional. Between tags.
74970 * @param string $after Optional. After tags.
74971 * @return string
74972 */
74973 function get_the_tag_list( $before = '', $sep = '', $after = '' ) {
74974 return apply_filters( 'the_tags', get_the_term_list( 0, 'post_tag', $before, $sep, $after ) );
74975 }
74976
74977 /**
74978 * Retrieve the tags for a post.
74979 *
74980 * @since 2.3.0
74981 *
74982 * @param string $before Optional. Before list.
74983 * @param string $sep Optional. Separate items using this.
74984 * @param string $after Optional. After list.
74985 * @return string
74986 */
74987 function the_tags( $before = 'Tags: ', $sep = ', ', $after = '' ) {
74988 return the_terms( 0, 'post_tag', $before, $sep, $after );
74989 }
74990
74991 /**
74992 * Retrieve the terms of the taxonomy that are attached to the post.
74993 *
74994 * This function can only be used within the loop.
74995 *
74996 * @since 2.5.0
74997 *
74998 * @param int $id Post ID. Is not optional.
74999 * @param string $taxonomy Taxonomy name.
75000 * @return array|bool False on failure. Array of term objects on success.
75001 */
75002 function get_the_terms( $id = 0, $taxonomy ) {
75003 global $post;
75004
75005 $id = (int) $id;
75006
75007 if ( ! $id && ! in_the_loop() )
75008 return false; // in-the-loop function
75009
75010 if ( !$id )
75011 $id = (int) $post->ID;
75012
75013 $terms = get_object_term_cache( $id, $taxonomy );
75014 if ( false === $terms )
75015 $terms = wp_get_object_terms( $id, $taxonomy );
75016
75017 if ( empty( $terms ) )
75018 return false;
75019
75020 return $terms;
75021 }
75022
75023 /**
75024 * Retrieve terms as a list with specified format.
75025 *
75026 * @since 2.5.0
75027 *
75028 * @param int $id Term ID.
75029 * @param string $taxonomy Taxonomy name.
75030 * @param string $before Optional. Before list.
75031 * @param string $sep Optional. Separate items using this.
75032 * @param string $after Optional. After list.
75033 * @return string
75034 */
75035 function get_the_term_list( $id = 0, $taxonomy, $before = '', $sep = '', $after = '' ) {
75036 $terms = get_the_terms( $id, $taxonomy );
75037
75038 if ( is_wp_error( $terms ) )
75039 return $terms;
75040
75041 if ( empty( $terms ) )
75042 return false;
75043
75044 foreach ( $terms as $term ) {
75045 $link = get_term_link( $term, $taxonomy );
75046 if ( is_wp_error( $link ) )
75047 return $link;
75048 $term_links[] = '<a href="' . $link . '" rel="tag">' . $term->name . '</a>';
75049 }
75050
75051 $term_links = apply_filters( "term_links-$taxonomy", $term_links );
75052
75053 return $before . join( $sep, $term_links ) . $after;
75054 }
75055
75056 /**
75057 * Display the terms in a list.
75058 *
75059 * @since 2.5.0
75060 *
75061 * @param int $id Term ID.
75062 * @param string $taxonomy Taxonomy name.
75063 * @param string $before Optional. Before list.
75064 * @param string $sep Optional. Separate items using this.
75065 * @param string $after Optional. After list.
75066 * @return null|bool False on WordPress error. Returns null when displaying.
75067 */
75068 function the_terms( $id, $taxonomy, $before = '', $sep = '', $after = '' ) {
75069 $return = get_the_term_list( $id, $taxonomy, $before, $sep, $after );
75070 if ( is_wp_error( $return ) )
75071 return false;
75072 else
75073 echo $return;
75074 }
75075
75076 /**
75077 * Check if the current post has any of given tags.
75078 *
75079 * The given tags are checked against the post's tags' term_ids, names and slugs.
75080 * Tags given as integers will only be checked against the post's tags' term_ids.
75081 * If no tags are given, determines if post has any tags.
75082 *
75083 * Prior to v2.7 of WordPress, tags given as integers would also be checked against the post's tags' names and slugs (in addition to term_ids)
75084 * Prior to v2.7, this function could only be used in the WordPress Loop.
75085 * As of 2.7, the function can be used anywhere if it is provided a post ID or post object.
75086 *
75087 * @since 2.6.0
75088 *
75089 * @uses is_object_in_term()
75090 *
75091 * @param string|int|array $tag Optional. The tag name/term_id/slug or array of them to check for.
75092 * @param int|post object Optional. Post to check instead of the current post. @since 2.7.0
75093 * @return bool True if the current post has any of the the given tags (or any tag, if no tag specified).
75094 */
75095 function has_tag( $tag = '', $_post = null ) {
75096 if ( $_post ) {
75097 $_post = get_post( $_post );
75098 } else {
75099 $_post =& $GLOBALS['post'];
75100 }
75101
75102 if ( !$_post )
75103 return false;
75104
75105 $r = is_object_in_term( $_post->ID, 'post_tag', $tag );
75106 if ( is_wp_error( $r ) )
75107 return false;
75108 return $r;
75109 }
75110
75111 ?>