Advertisement
Guest User

comments-template

a guest
Nov 13th, 2011
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 38.35 KB | None | 0 0
  1. application/x-httpd-php category-template.php
  2. PHP script text
  3.  
  4. <?php
  5. /**
  6.  * Category Template Tags and API.
  7.  *
  8.  * @package WordPress
  9.  * @subpackage Template
  10.  */
  11.  
  12. /**
  13.  * Retrieve category link URL.
  14.  *
  15.  * @since 1.0.0
  16.  * @see get_term_link()
  17.  *
  18.  * @param int|object $category Category ID or object.
  19.  * @return string Link on success, empty string if category does not exist.
  20.  */
  21. function get_category_link( $category ) {
  22.     if ( ! is_object( $category ) )
  23.         $category = (int) $category;
  24.  
  25.     $category = get_term_link( $category, 'category' );
  26.  
  27.     if ( is_wp_error( $category ) )
  28.         return '';
  29.  
  30.     return $category;
  31. }
  32.  
  33. /**
  34.  * Retrieve category parents with separator.
  35.  *
  36.  * @since 1.2.0
  37.  *
  38.  * @param int $id Category ID.
  39.  * @param bool $link Optional, default is false. Whether to format with link.
  40.  * @param string $separator Optional, default is '/'. How to separate categories.
  41.  * @param bool $nicename Optional, default is false. Whether to use nice name for display.
  42.  * @param array $visited Optional. Already linked to categories to prevent duplicates.
  43.  * @return string
  44.  */
  45. function get_category_parents( $id, $link = false, $separator = '/', $nicename = false, $visited = array() ) {
  46.     $chain = '';
  47.     $parent = &get_category( $id );
  48.     if ( is_wp_error( $parent ) )
  49.         return $parent;
  50.  
  51.     if ( $nicename )
  52.         $name = $parent->slug;
  53.     else
  54.         $name = $parent->name;
  55.  
  56.     if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) {
  57.         $visited[] = $parent->parent;
  58.         $chain .= get_category_parents( $parent->parent, $link, $separator, $nicename, $visited );
  59.     }
  60.  
  61.     if ( $link )
  62.         $chain .= '<a href="' . get_category_link( $parent->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $parent->name ) ) . '">'.$name.'</a>' . $separator;
  63.     else
  64.         $chain .= $name.$separator;
  65.     return $chain;
  66. }
  67.  
  68. /**
  69.  * Retrieve post categories.
  70.  *
  71.  * @since 0.71
  72.  * @uses $post
  73.  *
  74.  * @param int $id Optional, default to current post ID. The post ID.
  75.  * @return array
  76.  */
  77. function get_the_category( $id = false ) {
  78.     $categories = get_the_terms( $id, 'category' );
  79.     if ( ! $categories )
  80.         $categories = array();
  81.  
  82.     $categories = array_values( $categories );
  83.  
  84.     foreach ( array_keys( $categories ) as $key ) {
  85.         _make_cat_compat( $categories[$key] );
  86.     }
  87.  
  88.     // Filter name is plural because we return alot of categories (possibly more than #13237) not just one
  89.     return apply_filters( 'get_the_categories', $categories );
  90. }
  91.  
  92. /**
  93.  * Sort categories by name.
  94.  *
  95.  * Used by usort() as a callback, should not be used directly. Can actually be
  96.  * used to sort any term object.
  97.  *
  98.  * @since 2.3.0
  99.  * @access private
  100.  *
  101.  * @param object $a
  102.  * @param object $b
  103.  * @return int
  104.  */
  105. function _usort_terms_by_name( $a, $b ) {
  106.     return strcmp( $a->name, $b->name );
  107. }
  108.  
  109. /**
  110.  * Sort categories by ID.
  111.  *
  112.  * Used by usort() as a callback, should not be used directly. Can actually be
  113.  * used to sort any term object.
  114.  *
  115.  * @since 2.3.0
  116.  * @access private
  117.  *
  118.  * @param object $a
  119.  * @param object $b
  120.  * @return int
  121.  */
  122. function _usort_terms_by_ID( $a, $b ) {
  123.     if ( $a->term_id > $b->term_id )
  124.         return 1;
  125.     elseif ( $a->term_id < $b->term_id )
  126.         return -1;
  127.     else
  128.         return 0;
  129. }
  130.  
  131. /**
  132.  * Retrieve category name based on category ID.
  133.  *
  134.  * @since 0.71
  135.  *
  136.  * @param int $cat_ID Category ID.
  137.  * @return string Category name.
  138.  */
  139. function get_the_category_by_ID( $cat_ID ) {
  140.     $cat_ID = (int) $cat_ID;
  141.     $category = &get_category( $cat_ID );
  142.     if ( is_wp_error( $category ) )
  143.         return $category;
  144.     return $category->name;
  145. }
  146.  
  147. /**
  148.  * Retrieve category list in either HTML list or custom format.
  149.  *
  150.  * @since 1.5.1
  151.  *
  152.  * @param string $separator Optional, default is empty string. Separator for between the categories.
  153.  * @param string $parents Optional. How to display the parents.
  154.  * @param int $post_id Optional. Post ID to retrieve categories.
  155.  * @return string
  156.  */
  157. function get_the_category_list( $separator = '', $parents='', $post_id = false ) {
  158.     global $wp_rewrite;
  159.     $categories = get_the_category( $post_id );
  160.     if ( !is_object_in_taxonomy( get_post_type( $post_id ), 'category' ) )
  161.         return apply_filters( 'the_category', '', $separator, $parents );
  162.  
  163.     if ( empty( $categories ) )
  164.         return apply_filters( 'the_category', __( 'Uncategorized' ), $separator, $parents );
  165.  
  166.     $rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="category"';
  167.  
  168.     $thelist = '';
  169.     if ( '' == $separator ) {
  170.         $thelist .= '<ul class="post-categories">';
  171.         foreach ( $categories as $category ) {
  172.             $thelist .= "\n\t<li>";
  173.             switch ( strtolower( $parents ) ) {
  174.                 case 'multiple':
  175.                     if ( $category->parent )
  176.                         $thelist .= get_category_parents( $category->parent, true, $separator );
  177.                     $thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>' . $category->name.'</a></li>';
  178.                     break;
  179.                 case 'single':
  180.                     $thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>';
  181.                     if ( $category->parent )
  182.                         $thelist .= get_category_parents( $category->parent, false, $separator );
  183.                     $thelist .= $category->name.'</a></li>';
  184.                     break;
  185.                 case '':
  186.                 default:
  187.                     $thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>' . $category->name.'</a></li>';
  188.             }
  189.         }
  190.         $thelist .= '</ul>';
  191.     } else {
  192.         $i = 0;
  193.         foreach ( $categories as $category ) {
  194.             if ( 0 < $i )
  195.                 $thelist .= $separator;
  196.             switch ( strtolower( $parents ) ) {
  197.                 case 'multiple':
  198.                     if ( $category->parent )
  199.                         $thelist .= get_category_parents( $category->parent, true, $separator );
  200.                     $thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>' . $category->name.'</a>';
  201.                     break;
  202.                 case 'single':
  203.                     $thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>';
  204.                     if ( $category->parent )
  205.                         $thelist .= get_category_parents( $category->parent, false, $separator );
  206.                     $thelist .= "$category->name</a>";
  207.                     break;
  208.                 case '':
  209.                 default:
  210.                     $thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>' . $category->name.'</a>';
  211.             }
  212.             ++$i;
  213.         }
  214.     }
  215.     return apply_filters( 'the_category', $thelist, $separator, $parents );
  216. }
  217.  
  218.  
  219. /**
  220.  * Check if the current post in within any of the given categories.
  221.  *
  222.  * The given categories are checked against the post's categories' term_ids, names and slugs.
  223.  * Categories given as integers will only be checked against the post's categories' term_ids.
  224.  *
  225.  * Prior to v2.5 of WordPress, category names were not supported.
  226.  * Prior to v2.7, category slugs were not supported.
  227.  * Prior to v2.7, only one category could be compared: in_category( $single_category ).
  228.  * Prior to v2.7, this function could only be used in the WordPress Loop.
  229.  * As of 2.7, the function can be used anywhere if it is provided a post ID or post object.
  230.  *
  231.  * @since 1.2.0
  232.  *
  233.  * @param int|string|array $category Category ID, name or slug, or array of said.
  234.  * @param int|object $_post Optional. Post to check instead of the current post. (since 2.7.0)
  235.  * @return bool True if the current post is in any of the given categories.
  236.  */
  237. function in_category( $category, $post = null ) {
  238.     if ( empty( $category ) )
  239.         return false;
  240.  
  241.     return has_term( $category, 'category', $post );
  242. }
  243.  
  244. /**
  245.  * Display the category list for the post.
  246.  *
  247.  * @since 0.71
  248.  *
  249.  * @param string $separator Optional, default is empty string. Separator for between the categories.
  250.  * @param string $parents Optional. How to display the parents.
  251.  * @param int $post_id Optional. Post ID to retrieve categories.
  252.  */
  253. function the_category( $separator = '', $parents='', $post_id = false ) {
  254.     echo get_the_category_list( $separator, $parents, $post_id );
  255. }
  256.  
  257. /**
  258.  * Retrieve category description.
  259.  *
  260.  * @since 1.0.0
  261.  *
  262.  * @param int $category Optional. Category ID. Will use global category ID by default.
  263.  * @return string Category description, available.
  264.  */
  265. function category_description( $category = 0 ) {
  266.     return term_description( $category, 'category' );
  267. }
  268.  
  269. /**
  270.  * Display or retrieve the HTML dropdown list of categories.
  271.  *
  272.  * The list of arguments is below:
  273.  *     'show_option_all' (string) - Text to display for showing all categories.
  274.  *     'show_option_none' (string) - Text to display for showing no categories.
  275.  *     'orderby' (string) default is 'ID' - What column to use for ordering the
  276.  * categories.
  277.  *     'order' (string) default is 'ASC' - What direction to order categories.
  278.  *     'show_last_update' (bool|int) default is 0 - See {@link get_categories()}
  279.  *     'show_count' (bool|int) default is 0 - Whether to show how many posts are
  280.  * in the category.
  281.  *     'hide_empty' (bool|int) default is 1 - Whether to hide categories that
  282.  * don't have any posts attached to them.
  283.  *     'child_of' (int) default is 0 - See {@link get_categories()}.
  284.  *     'exclude' (string) - See {@link get_categories()}.
  285.  *     'echo' (bool|int) default is 1 - Whether to display or retrieve content.
  286.  *     'depth' (int) - The max depth.
  287.  *     'tab_index' (int) - Tab index for select element.
  288.  *     'name' (string) - The name attribute value for select element.
  289.  *     'id' (string) - The ID attribute value for select element. Defaults to name if omitted.
  290.  *     'class' (string) - The class attribute value for select element.
  291.  *     'selected' (int) - Which category ID is selected.
  292.  *     'taxonomy' (string) - The name of the taxonomy to retrieve. Defaults to category.
  293.  *
  294.  * The 'hierarchical' argument, which is disabled by default, will override the
  295.  * depth argument, unless it is true. When the argument is false, it will
  296.  * display all of the categories. When it is enabled it will use the value in
  297.  * the 'depth' argument.
  298.  *
  299.  * @since 2.1.0
  300.  *
  301.  * @param string|array $args Optional. Override default arguments.
  302.  * @return string HTML content only if 'echo' argument is 0.
  303.  */
  304. function wp_dropdown_categories( $args = '' ) {
  305.     $defaults = array(
  306.         'show_option_all' => '', 'show_option_none' => '',
  307.         'orderby' => 'id', 'order' => 'ASC',
  308.         'show_last_update' => 0, 'show_count' => 0,
  309.         'hide_empty' => 1, 'child_of' => 0,
  310.         'exclude' => '', 'echo' => 1,
  311.         'selected' => 0, 'hierarchical' => 0,
  312.         'name' => 'cat', 'id' => '',
  313.         'class' => 'postform', 'depth' => 0,
  314.         'tab_index' => 0, 'taxonomy' => 'category',
  315.         'hide_if_empty' => false
  316.     );
  317.  
  318.     $defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0;
  319.  
  320.     // Back compat.
  321.     if ( isset( $args['type'] ) && 'link' == $args['type'] ) {
  322.         _deprecated_argument( __FUNCTION__, '3.0', '' );
  323.         $args['taxonomy'] = 'link_category';
  324.     }
  325.  
  326.     $r = wp_parse_args( $args, $defaults );
  327.  
  328.     if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
  329.         $r['pad_counts'] = true;
  330.     }
  331.  
  332.     $r['include_last_update_time'] = $r['show_last_update'];
  333.     extract( $r );
  334.  
  335.     $tab_index_attribute = '';
  336.     if ( (int) $tab_index > 0 )
  337.         $tab_index_attribute = " tabindex=\"$tab_index\"";
  338.  
  339.     $categories = get_terms( $taxonomy, $r );
  340.     $name = esc_attr( $name );
  341.     $class = esc_attr( $class );
  342.     $id = $id ? esc_attr( $id ) : $name;
  343.  
  344.     if ( ! $r['hide_if_empty'] || ! empty($categories) )
  345.         $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n";
  346.     else
  347.         $output = '';
  348.  
  349.     if ( empty($categories) && ! $r['hide_if_empty'] && !empty($show_option_none) ) {
  350.         $show_option_none = apply_filters( 'list_cats', $show_option_none );
  351.         $output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n";
  352.     }
  353.  
  354.     if ( ! empty( $categories ) ) {
  355.  
  356.         if ( $show_option_all ) {
  357.             $show_option_all = apply_filters( 'list_cats', $show_option_all );
  358.             $selected = ( '0' === strval($r['selected']) ) ? " selected='selected'" : '';
  359.             $output .= "\t<option value='0'$selected>$show_option_all</option>\n";
  360.         }
  361.  
  362.         if ( $show_option_none ) {
  363.             $show_option_none = apply_filters( 'list_cats', $show_option_none );
  364.             $selected = ( '-1' === strval($r['selected']) ) ? " selected='selected'" : '';
  365.             $output .= "\t<option value='-1'$selected>$show_option_none</option>\n";
  366.         }
  367.  
  368.         if ( $hierarchical )
  369.             $depth = $r['depth'];  // Walk the full depth.
  370.         else
  371.             $depth = -1; // Flat.
  372.  
  373.         $output .= walk_category_dropdown_tree( $categories, $depth, $r );
  374.     }
  375.     if ( ! $r['hide_if_empty'] || ! empty($categories) )
  376.         $output .= "</select>\n";
  377.  
  378.  
  379.     $output = apply_filters( 'wp_dropdown_cats', $output );
  380.  
  381.     if ( $echo )
  382.         echo $output;
  383.  
  384.     return $output;
  385. }
  386.  
  387. /**
  388.  * Display or retrieve the HTML list of categories.
  389.  *
  390.  * The list of arguments is below:
  391.  *     'show_option_all' (string) - Text to display for showing all categories.
  392.  *     'orderby' (string) default is 'ID' - What column to use for ordering the
  393.  * categories.
  394.  *     'order' (string) default is 'ASC' - What direction to order categories.
  395.  *     'show_last_update' (bool|int) default is 0 - See {@link
  396.  * walk_category_dropdown_tree()}
  397.  *     'show_count' (bool|int) default is 0 - Whether to show how many posts are
  398.  * in the category.
  399.  *     'hide_empty' (bool|int) default is 1 - Whether to hide categories that
  400.  * don't have any posts attached to them.
  401.  *     'use_desc_for_title' (bool|int) default is 1 - Whether to use the
  402.  * description instead of the category title.
  403.  *     'feed' - See {@link get_categories()}.
  404.  *     'feed_type' - See {@link get_categories()}.
  405.  *     'feed_image' - See {@link get_categories()}.
  406.  *     'child_of' (int) default is 0 - See {@link get_categories()}.
  407.  *     'exclude' (string) - See {@link get_categories()}.
  408.  *     'exclude_tree' (string) - See {@link get_categories()}.
  409.  *     'echo' (bool|int) default is 1 - Whether to display or retrieve content.
  410.  *     'current_category' (int) - See {@link get_categories()}.
  411.  *     'hierarchical' (bool) - See {@link get_categories()}.
  412.  *     'title_li' (string) - See {@link get_categories()}.
  413.  *     'depth' (int) - The max depth.
  414.  *
  415.  * @since 2.1.0
  416.  *
  417.  * @param string|array $args Optional. Override default arguments.
  418.  * @return string HTML content only if 'echo' argument is 0.
  419.  */
  420. function wp_list_categories( $args = '' ) {
  421.     $defaults = array(
  422.         'show_option_all' => '', 'show_option_none' => __('No categories'),
  423.         'orderby' => 'name', 'order' => 'ASC',
  424.         'show_last_update' => 0, 'style' => 'list',
  425.         'show_count' => 0, 'hide_empty' => 1,
  426.         'use_desc_for_title' => 1, 'child_of' => 0,
  427.         'feed' => '', 'feed_type' => '',
  428.         'feed_image' => '', 'exclude' => '',
  429.         'exclude_tree' => '', 'current_category' => 0,
  430.         'hierarchical' => true, 'title_li' => __( 'Categories' ),
  431.         'echo' => 1, 'depth' => 0,
  432.         'taxonomy' => 'category'
  433.     );
  434.  
  435.     $r = wp_parse_args( $args, $defaults );
  436.  
  437.     if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] )
  438.         $r['pad_counts'] = true;
  439.  
  440.     if ( isset( $r['show_date'] ) )
  441.         $r['include_last_update_time'] = $r['show_date'];
  442.  
  443.     if ( true == $r['hierarchical'] ) {
  444.         $r['exclude_tree'] = $r['exclude'];
  445.         $r['exclude'] = '';
  446.     }
  447.  
  448.     if ( !isset( $r['class'] ) )
  449.         $r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy'];
  450.  
  451.     extract( $r );
  452.  
  453.     if ( !taxonomy_exists($taxonomy) )
  454.         return false;
  455.  
  456.     $categories = get_categories( $r );
  457.  
  458.     $output = '';
  459.     if ( $title_li && 'list' == $style )
  460.             $output = '<li class="' . esc_attr( $class ) . '">' . $title_li . '<ul>';
  461.  
  462.     if ( empty( $categories ) ) {
  463.         if ( ! empty( $show_option_none ) ) {
  464.             if ( 'list' == $style )
  465.                 $output .= '<li>' . $show_option_none . '</li>';
  466.             else
  467.                 $output .= $show_option_none;
  468.         }
  469.     } else {
  470.         if( !empty( $show_option_all ) )
  471.             if ( 'list' == $style )
  472.                 $output .= '<li><a href="' .  get_bloginfo( 'url' )  . '">' . $show_option_all . '</a></li>';
  473.             else
  474.                 $output .= '<a href="' .  get_bloginfo( 'url' )  . '">' . $show_option_all . '</a>';
  475.  
  476.         if ( empty( $r['current_category'] ) && ( is_category() || is_tax() || is_tag() ) ) {
  477.             $current_term_object = get_queried_object();
  478.             if ( $r['taxonomy'] == $current_term_object->taxonomy )
  479.                 $r['current_category'] = get_queried_object_id();
  480.         }
  481.  
  482.         if ( $hierarchical )
  483.             $depth = $r['depth'];
  484.         else
  485.             $depth = -1; // Flat.
  486.  
  487.         $output .= walk_category_tree( $categories, $depth, $r );
  488.     }
  489.  
  490.     if ( $title_li && 'list' == $style )
  491.         $output .= '</ul></li>';
  492.  
  493.     $output = apply_filters( 'wp_list_categories', $output, $args );
  494.  
  495.     if ( $echo )
  496.         echo $output;
  497.     else
  498.         return $output;
  499. }
  500.  
  501. /**
  502.  * Display tag cloud.
  503.  *
  504.  * The text size is set by the 'smallest' and 'largest' arguments, which will
  505.  * use the 'unit' argument value for the CSS text size unit. The 'format'
  506.  * argument can be 'flat' (default), 'list', or 'array'. The flat value for the
  507.  * 'format' argument will separate tags with spaces. The list value for the
  508.  * 'format' argument will format the tags in a UL HTML list. The array value for
  509.  * the 'format' argument will return in PHP array type format.
  510.  *
  511.  * The 'orderby' argument will accept 'name' or 'count' and defaults to 'name'.
  512.  * The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC'.
  513.  *
  514.  * The 'number' argument is how many tags to return. By default, the limit will
  515.  * be to return the top 45 tags in the tag cloud list.
  516.  *
  517.  * The 'topic_count_text_callback' argument is a function, which, given the count
  518.  * of the posts  with that tag, returns a text for the tooltip of the tag link.
  519.  *
  520.  * The 'exclude' and 'include' arguments are used for the {@link get_tags()}
  521.  * function. Only one should be used, because only one will be used and the
  522.  * other ignored, if they are both set.
  523.  *
  524.  * @since 2.3.0
  525.  *
  526.  * @param array|string $args Optional. Override default arguments.
  527.  * @return array Generated tag cloud, only if no failures and 'array' is set for the 'format' argument.
  528.  */
  529. function wp_tag_cloud( $args = '' ) {
  530.     $defaults = array(
  531.         'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
  532.         'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
  533.         'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true
  534.     );
  535.     $args = wp_parse_args( $args, $defaults );
  536.  
  537.     $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags
  538.  
  539.     if ( empty( $tags ) || is_wp_error( $tags ) )
  540.         return;
  541.  
  542.     foreach ( $tags as $key => $tag ) {
  543.         if ( 'edit' == $args['link'] )
  544.             $link = get_edit_tag_link( $tag->term_id, $tag->taxonomy );
  545.         else
  546.             $link = get_term_link( intval($tag->term_id), $tag->taxonomy );
  547.         if ( is_wp_error( $link ) )
  548.             return false;
  549.  
  550.         $tags[ $key ]->link = $link;
  551.         $tags[ $key ]->id = $tag->term_id;
  552.     }
  553.  
  554.     $return = wp_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args
  555.  
  556.     $return = apply_filters( 'wp_tag_cloud', $return, $args );
  557.  
  558.     if ( 'array' == $args['format'] || empty($args['echo']) )
  559.         return $return;
  560.  
  561.     echo $return;
  562. }
  563.  
  564. /**
  565.  * Default text for tooltip for tag links
  566.  *
  567.  * @param integer $count number of posts with that tag
  568.  * @return string text for the tooltip of a tag link.
  569.  */
  570. function default_topic_count_text( $count ) {
  571.     return sprintf( _n('%s topic', '%s topics', $count), number_format_i18n( $count ) );
  572. }
  573.  
  574. /**
  575.  * Default topic count scaling for tag links
  576.  *
  577.  * @param integer $count number of posts with that tag
  578.  * @return integer scaled count
  579.  */
  580. function default_topic_count_scale( $count ) {
  581.     return round(log10($count + 1) * 100);
  582. }
  583.  
  584.  
  585. /**
  586.  * Generates a tag cloud (heatmap) from provided data.
  587.  *
  588.  * The text size is set by the 'smallest' and 'largest' arguments, which will
  589.  * use the 'unit' argument value for the CSS text size unit. The 'format'
  590.  * argument can be 'flat' (default), 'list', or 'array'. The flat value for the
  591.  * 'format' argument will separate tags with spaces. The list value for the
  592.  * 'format' argument will format the tags in a UL HTML list. The array value for
  593.  * the 'format' argument will return in PHP array type format.
  594.  *
  595.  * The 'tag_cloud_sort' filter allows you to override the sorting.
  596.  * Passed to the filter: $tags array and $args array, has to return the $tags array
  597.  * after sorting it.
  598.  *
  599.  * The 'orderby' argument will accept 'name' or 'count' and defaults to 'name'.
  600.  * The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC' or
  601.  * 'RAND'.
  602.  *
  603.  * The 'number' argument is how many tags to return. By default, the limit will
  604.  * be to return the entire tag cloud list.
  605.  *
  606.  * The 'topic_count_text_callback' argument is a function, which given the count
  607.  * of the posts  with that tag returns a text for the tooltip of the tag link.
  608.  *
  609.  * @todo Complete functionality.
  610.  * @since 2.3.0
  611.  *
  612.  * @param array $tags List of tags.
  613.  * @param string|array $args Optional, override default arguments.
  614.  * @return string
  615.  */
  616. function wp_generate_tag_cloud( $tags, $args = '' ) {
  617.     global $wp_rewrite;
  618.     $defaults = array(
  619.         'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0,
  620.         'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
  621.         'topic_count_text_callback' => 'default_topic_count_text',
  622.         'topic_count_scale_callback' => 'default_topic_count_scale', 'filter' => 1,
  623.     );
  624.  
  625.     if ( !isset( $args['topic_count_text_callback'] ) && isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) {
  626.         $body = 'return sprintf (
  627.             _n(' . var_export($args['single_text'], true) . ', ' . var_export($args['multiple_text'], true) . ', $count),
  628.             number_format_i18n( $count ));';
  629.         $args['topic_count_text_callback'] = create_function('$count', $body);
  630.     }
  631.  
  632.     $args = wp_parse_args( $args, $defaults );
  633.     extract( $args );
  634.  
  635.     if ( empty( $tags ) )
  636.         return;
  637.  
  638.     $tags_sorted = apply_filters( 'tag_cloud_sort', $tags, $args );
  639.     if ( $tags_sorted != $tags  ) { // the tags have been sorted by a plugin
  640.         $tags = $tags_sorted;
  641.         unset($tags_sorted);
  642.     } else {
  643.         if ( 'RAND' == $order ) {
  644.             shuffle($tags);
  645.         } else {
  646.             // SQL cannot save you; this is a second (potentially different) sort on a subset of data.
  647.             if ( 'name' == $orderby )
  648.                 uasort( $tags, create_function('$a, $b', 'return strnatcasecmp($a->name, $b->name);') );
  649.             else
  650.                 uasort( $tags, create_function('$a, $b', 'return ($a->count > $b->count);') );
  651.  
  652.             if ( 'DESC' == $order )
  653.                 $tags = array_reverse( $tags, true );
  654.         }
  655.     }
  656.  
  657.     if ( $number > 0 )
  658.         $tags = array_slice($tags, 0, $number);
  659.  
  660.     $counts = array();
  661.     $real_counts = array(); // For the alt tag
  662.     foreach ( (array) $tags as $key => $tag ) {
  663.         $real_counts[ $key ] = $tag->count;
  664.         $counts[ $key ] = $topic_count_scale_callback($tag->count);
  665.     }
  666.  
  667.     $min_count = min( $counts );
  668.     $spread = max( $counts ) - $min_count;
  669.     if ( $spread <= 0 )
  670.         $spread = 1;
  671.     $font_spread = $largest - $smallest;
  672.     if ( $font_spread < 0 )
  673.         $font_spread = 1;
  674.     $font_step = $font_spread / $spread;
  675.  
  676.     $a = array();
  677.  
  678.     foreach ( $tags as $key => $tag ) {
  679.         $count = $counts[ $key ];
  680.         $real_count = $real_counts[ $key ];
  681.         $tag_link = '#' != $tag->link ? esc_url( $tag->link ) : '#';
  682.         $tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key;
  683.         $tag_name = $tags[ $key ]->name;
  684.         $a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . esc_attr( call_user_func( $topic_count_text_callback, $real_count ) ) . "' style='font-size: " .
  685.             ( $smallest + ( ( $count - $min_count ) * $font_step ) )
  686.             . "$unit;'>$tag_name</a>";
  687.     }
  688.  
  689.     switch ( $format ) :
  690.     case 'array' :
  691.         $return =& $a;
  692.         break;
  693.     case 'list' :
  694.         $return = "<ul class='wp-tag-cloud'>\n\t<li>";
  695.         $return .= join( "</li>\n\t<li>", $a );
  696.         $return .= "</li>\n</ul>\n";
  697.         break;
  698.     default :
  699.         $return = join( $separator, $a );
  700.         break;
  701.     endswitch;
  702.  
  703.     if ( $filter )
  704.         return apply_filters( 'wp_generate_tag_cloud', $return, $tags, $args );
  705.     else
  706.         return $return;
  707. }
  708.  
  709. /**
  710.  * Callback for comparing tags based on name
  711.  *
  712.  * @since 3.1.0
  713.  * @access private
  714.  */
  715. function _wp_tag_cloud_name_sort_cb( $a, $b ) {
  716.     return strnatcasecmp( $a->name, $b->name );
  717. }
  718.  
  719. /**
  720.  * Callback for comparing tags based on count
  721.  *
  722.  * @since 3.1.0
  723.  * @access private
  724.  */
  725. function _wp_tag_cloud_count_sort_cb( $a, $b ) {
  726.     return ( $a->count > $b->count );
  727. }
  728.  
  729. //
  730. // Helper functions
  731. //
  732.  
  733. /**
  734.  * Retrieve HTML list content for category list.
  735.  *
  736.  * @uses Walker_Category to create HTML list content.
  737.  * @since 2.1.0
  738.  * @see Walker_Category::walk() for parameters and return description.
  739.  */
  740. function walk_category_tree() {
  741.     $args = func_get_args();
  742.     // the user's options are the third parameter
  743.     if ( empty($args[2]['walker']) || !is_a($args[2]['walker'], 'Walker') )
  744.         $walker = new Walker_Category;
  745.     else
  746.         $walker = $args[2]['walker'];
  747.  
  748.     return call_user_func_array(array( &$walker, 'walk' ), $args );
  749. }
  750.  
  751. /**
  752.  * Retrieve HTML dropdown (select) content for category list.
  753.  *
  754.  * @uses Walker_CategoryDropdown to create HTML dropdown content.
  755.  * @since 2.1.0
  756.  * @see Walker_CategoryDropdown::walk() for parameters and return description.
  757.  */
  758. function walk_category_dropdown_tree() {
  759.     $args = func_get_args();
  760.     // the user's options are the third parameter
  761.     if ( empty($args[2]['walker']) || !is_a($args[2]['walker'], 'Walker') )
  762.         $walker = new Walker_CategoryDropdown;
  763.     else
  764.         $walker = $args[2]['walker'];
  765.  
  766.     return call_user_func_array(array( &$walker, 'walk' ), $args );
  767. }
  768.  
  769. /**
  770.  * Create HTML list of categories.
  771.  *
  772.  * @package WordPress
  773.  * @since 2.1.0
  774.  * @uses Walker
  775.  */
  776. class Walker_Category extends Walker {
  777.     /**
  778.      * @see Walker::$tree_type
  779.      * @since 2.1.0
  780.      * @var string
  781.      */
  782.     var $tree_type = 'category';
  783.  
  784.     /**
  785.      * @see Walker::$db_fields
  786.      * @since 2.1.0
  787.      * @todo Decouple this
  788.      * @var array
  789.      */
  790.     var $db_fields = array ('parent' => 'parent', 'id' => 'term_id');
  791.  
  792.     /**
  793.      * @see Walker::start_lvl()
  794.      * @since 2.1.0
  795.      *
  796.      * @param string $output Passed by reference. Used to append additional content.
  797.      * @param int $depth Depth of category. Used for tab indentation.
  798.      * @param array $args Will only append content if style argument value is 'list'.
  799.      */
  800.     function start_lvl(&$output, $depth, $args) {
  801.         if ( 'list' != $args['style'] )
  802.             return;
  803.  
  804.         $indent = str_repeat("\t", $depth);
  805.         $output .= "$indent<ul class='children'>\n";
  806.     }
  807.  
  808.     /**
  809.      * @see Walker::end_lvl()
  810.      * @since 2.1.0
  811.      *
  812.      * @param string $output Passed by reference. Used to append additional content.
  813.      * @param int $depth Depth of category. Used for tab indentation.
  814.      * @param array $args Will only append content if style argument value is 'list'.
  815.      */
  816.     function end_lvl(&$output, $depth, $args) {
  817.         if ( 'list' != $args['style'] )
  818.             return;
  819.  
  820.         $indent = str_repeat("\t", $depth);
  821.         $output .= "$indent</ul>\n";
  822.     }
  823.  
  824.     /**
  825.      * @see Walker::start_el()
  826.      * @since 2.1.0
  827.      *
  828.      * @param string $output Passed by reference. Used to append additional content.
  829.      * @param object $category Category data object.
  830.      * @param int $depth Depth of category in reference to parents.
  831.      * @param array $args
  832.      */
  833.     function start_el(&$output, $category, $depth, $args) {
  834.         extract($args);
  835.  
  836.         $cat_name = esc_attr( $category->name );
  837.         $cat_name = apply_filters( 'list_cats', $cat_name, $category );
  838.         $link = '<a href="' . esc_attr( get_term_link($category) ) . '" ';
  839.         if ( $use_desc_for_title == 0 || empty($category->description) )
  840.             $link .= 'title="' . esc_attr( sprintf(__( 'View all posts filed under %s' ), $cat_name) ) . '"';
  841.         else
  842.             $link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"';
  843.         $link .= '>';
  844.         $link .= $cat_name . '</a>';
  845.  
  846.         if ( !empty($feed_image) || !empty($feed) ) {
  847.             $link .= ' ';
  848.  
  849.             if ( empty($feed_image) )
  850.                 $link .= '(';
  851.  
  852.             $link .= '<a href="' . get_term_feed_link( $category->term_id, $category->taxonomy, $feed_type ) . '"';
  853.  
  854.             if ( empty($feed) ) {
  855.                 $alt = ' alt="' . sprintf(__( 'Feed for all posts filed under %s' ), $cat_name ) . '"';
  856.             } else {
  857.                 $title = ' title="' . $feed . '"';
  858.                 $alt = ' alt="' . $feed . '"';
  859.                 $name = $feed;
  860.                 $link .= $title;
  861.             }
  862.  
  863.             $link .= '>';
  864.  
  865.             if ( empty($feed_image) )
  866.                 $link .= $name;
  867.             else
  868.                 $link .= "<img src='$feed_image'$alt$title" . ' />';
  869.  
  870.             $link .= '</a>';
  871.  
  872.             if ( empty($feed_image) )
  873.                 $link .= ')';
  874.         }
  875.  
  876.         if ( !empty($show_count) )
  877.             $link .= ' (' . intval($category->count) . ')';
  878.  
  879.         if ( !empty($show_date) )
  880.             $link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp);
  881.  
  882.         if ( 'list' == $args['style'] ) {
  883.             $output .= "\t<li";
  884.             $class = 'cat-item cat-item-' . $category->term_id;
  885.             if ( !empty($current_category) ) {
  886.                 $_current_category = get_term( $current_category, $category->taxonomy );
  887.                 if ( $category->term_id == $current_category )
  888.                     $class .=  ' current-cat';
  889.                 elseif ( $category->term_id == $_current_category->parent )
  890.                     $class .=  ' current-cat-parent';
  891.             }
  892.             $output .=  ' class="' . $class . '"';
  893.             $output .= ">$link\n";
  894.         } else {
  895.             $output .= "\t$link<br />\n";
  896.         }
  897.     }
  898.  
  899.     /**
  900.      * @see Walker::end_el()
  901.      * @since 2.1.0
  902.      *
  903.      * @param string $output Passed by reference. Used to append additional content.
  904.      * @param object $page Not used.
  905.      * @param int $depth Depth of category. Not used.
  906.      * @param array $args Only uses 'list' for whether should append to output.
  907.      */
  908.     function end_el(&$output, $page, $depth, $args) {
  909.         if ( 'list' != $args['style'] )
  910.             return;
  911.  
  912.         $output .= "</li>\n";
  913.     }
  914.  
  915. }
  916.  
  917. /**
  918.  * Create HTML dropdown list of Categories.
  919.  *
  920.  * @package WordPress
  921.  * @since 2.1.0
  922.  * @uses Walker
  923.  */
  924. class Walker_CategoryDropdown extends Walker {
  925.     /**
  926.      * @see Walker::$tree_type
  927.      * @since 2.1.0
  928.      * @var string
  929.      */
  930.     var $tree_type = 'category';
  931.  
  932.     /**
  933.      * @see Walker::$db_fields
  934.      * @since 2.1.0
  935.      * @todo Decouple this
  936.      * @var array
  937.      */
  938.     var $db_fields = array ('parent' => 'parent', 'id' => 'term_id');
  939.  
  940.     /**
  941.      * @see Walker::start_el()
  942.      * @since 2.1.0
  943.      *
  944.      * @param string $output Passed by reference. Used to append additional content.
  945.      * @param object $category Category data object.
  946.      * @param int $depth Depth of category. Used for padding.
  947.      * @param array $args Uses 'selected', 'show_count', and 'show_last_update' keys, if they exist.
  948.      */
  949.     function start_el(&$output, $category, $depth, $args) {
  950.         $pad = str_repeat('&nbsp;', $depth * 3);
  951.  
  952.         $cat_name = apply_filters('list_cats', $category->name, $category);
  953.         $output .= "\t<option class=\"level-$depth\" value=\"".$category->term_id."\"";
  954.         if ( $category->term_id == $args['selected'] )
  955.             $output .= ' selected="selected"';
  956.         $output .= '>';
  957.         $output .= $pad.$cat_name;
  958.         if ( $args['show_count'] )
  959.             $output .= '&nbsp;&nbsp;('. $category->count .')';
  960.         if ( $args['show_last_update'] ) {
  961.             $format = 'Y-m-d';
  962.             $output .= '&nbsp;&nbsp;' . gmdate($format, $category->last_update_timestamp);
  963.         }
  964.         $output .= "</option>\n";
  965.     }
  966. }
  967.  
  968. //
  969. // Tags
  970. //
  971.  
  972. /**
  973.  * Retrieve the link to the tag.
  974.  *
  975.  * @since 2.3.0
  976.  * @see get_term_link()
  977.  *
  978.  * @param int|object $tag Tag ID or object.
  979.  * @return string Link on success, empty string if tag does not exist.
  980.  */
  981. function get_tag_link( $tag ) {
  982.     if ( ! is_object( $tag ) )
  983.         $tag = (int) $tag;
  984.  
  985.     $tag = get_term_link( $tag, 'post_tag' );
  986.  
  987.     if ( is_wp_error( $tag ) )
  988.         return '';
  989.  
  990.     return $tag;
  991. }
  992.  
  993. /**
  994.  * Retrieve the tags for a post.
  995.  *
  996.  * @since 2.3.0
  997.  * @uses apply_filters() Calls 'get_the_tags' filter on the list of post tags.
  998.  *
  999.  * @param int $id Post ID.
  1000.  * @return array
  1001.  */
  1002. function get_the_tags( $id = 0 ) {
  1003.     return apply_filters( 'get_the_tags', get_the_terms( $id, 'post_tag' ) );
  1004. }
  1005.  
  1006. /**
  1007.  * Retrieve the tags for a post formatted as a string.
  1008.  *
  1009.  * @since 2.3.0
  1010.  * @uses apply_filters() Calls 'the_tags' filter on string list of tags.
  1011.  *
  1012.  * @param string $before Optional. Before tags.
  1013.  * @param string $sep Optional. Between tags.
  1014.  * @param string $after Optional. After tags.
  1015.  * @return string
  1016.  */
  1017. function get_the_tag_list( $before = '', $sep = '', $after = '' ) {
  1018.     return apply_filters( 'the_tags', get_the_term_list( 0, 'post_tag', $before, $sep, $after ), $before, $sep, $after);
  1019. }
  1020.  
  1021. /**
  1022.  * Retrieve the tags for a post.
  1023.  *
  1024.  * @since 2.3.0
  1025.  *
  1026.  * @param string $before Optional. Before list.
  1027.  * @param string $sep Optional. Separate items using this.
  1028.  * @param string $after Optional. After list.
  1029.  * @return string
  1030.  */
  1031. function the_tags( $before = null, $sep = ', ', $after = '' ) {
  1032.     if ( null === $before )
  1033.         $before = __('Tags: ');
  1034.     echo get_the_tag_list($before, $sep, $after);
  1035. }
  1036.  
  1037. /**
  1038.  * Retrieve tag description.
  1039.  *
  1040.  * @since 2.8
  1041.  *
  1042.  * @param int $tag Optional. Tag ID. Will use global tag ID by default.
  1043.  * @return string Tag description, available.
  1044.  */
  1045. function tag_description( $tag = 0 ) {
  1046.     return term_description( $tag );
  1047. }
  1048.  
  1049. /**
  1050.  * Retrieve term description.
  1051.  *
  1052.  * @since 2.8
  1053.  *
  1054.  * @param int $term Optional. Term ID. Will use global term ID by default.
  1055.  * @return string Term description, available.
  1056.  */
  1057. function term_description( $term = 0, $taxonomy = 'post_tag' ) {
  1058.     if ( !$term && ( is_tax() || is_tag() || is_category() ) ) {
  1059.         $term = get_queried_object();
  1060.         $taxonomy = $term->taxonomy;
  1061.         $term = $term->term_id;
  1062.     }
  1063.     $description = get_term_field( 'description', $term, $taxonomy );
  1064.     return is_wp_error( $description ) ? '' : $description;
  1065. }
  1066.  
  1067. /**
  1068.  * Retrieve the terms of the taxonomy that are attached to the post.
  1069.  *
  1070.  * @since 2.5.0
  1071.  *
  1072.  * @param int $id Post ID. Is not optional.
  1073.  * @param string $taxonomy Taxonomy name.
  1074.  * @return array|bool False on failure. Array of term objects on success.
  1075.  */
  1076. function get_the_terms( $id = 0, $taxonomy ) {
  1077.     global $post;
  1078.  
  1079.     $id = (int) $id;
  1080.  
  1081.     if ( !$id ) {
  1082.         if ( !$post->ID )
  1083.             return false;
  1084.         else
  1085.             $id = (int) $post->ID;
  1086.     }
  1087.  
  1088.     $terms = get_object_term_cache( $id, $taxonomy );
  1089.     if ( false === $terms ) {
  1090.         $terms = wp_get_object_terms( $id, $taxonomy );
  1091.         wp_cache_add($id, $terms, $taxonomy . '_relationships');
  1092.     }
  1093.  
  1094.     $terms = apply_filters( 'get_the_terms', $terms, $id, $taxonomy );
  1095.  
  1096.     if ( empty( $terms ) )
  1097.         return false;
  1098.  
  1099.     return $terms;
  1100. }
  1101.  
  1102. /**
  1103.  * Retrieve a post's terms as a list with specified format.
  1104.  *
  1105.  * @since 2.5.0
  1106.  *
  1107.  * @param int $id Post ID.
  1108.  * @param string $taxonomy Taxonomy name.
  1109.  * @param string $before Optional. Before list.
  1110.  * @param string $sep Optional. Separate items using this.
  1111.  * @param string $after Optional. After list.
  1112.  * @return string
  1113.  */
  1114. function get_the_term_list( $id = 0, $taxonomy, $before = '', $sep = '', $after = '' ) {
  1115.     $terms = get_the_terms( $id, $taxonomy );
  1116.  
  1117.     if ( is_wp_error( $terms ) )
  1118.         return $terms;
  1119.  
  1120.     if ( empty( $terms ) )
  1121.         return false;
  1122.  
  1123.     foreach ( $terms as $term ) {
  1124.         $link = get_term_link( $term, $taxonomy );
  1125.         if ( is_wp_error( $link ) )
  1126.             return $link;
  1127.         $term_links[] = '<a href="' . $link . '" rel="tag">' . $term->name . '</a>';
  1128.     }
  1129.  
  1130.     $term_links = apply_filters( "term_links-$taxonomy", $term_links );
  1131.  
  1132.     return $before . join( $sep, $term_links ) . $after;
  1133. }
  1134.  
  1135. /**
  1136.  * Display the terms in a list.
  1137.  *
  1138.  * @since 2.5.0
  1139.  *
  1140.  * @param int $id Post ID.
  1141.  * @param string $taxonomy Taxonomy name.
  1142.  * @param string $before Optional. Before list.
  1143.  * @param string $sep Optional. Separate items using this.
  1144.  * @param string $after Optional. After list.
  1145.  * @return null|bool False on WordPress error. Returns null when displaying.
  1146.  */
  1147. function the_terms( $id = 0, $taxonomy, $before = '', $sep = ', ', $after = '' ) {
  1148.     $term_list = get_the_term_list( $id, $taxonomy, $before, $sep, $after );
  1149.  
  1150.     if ( is_wp_error( $term_list ) )
  1151.         return false;
  1152.  
  1153.     echo apply_filters('the_terms', $term_list, $taxonomy, $before, $sep, $after);
  1154. }
  1155.  
  1156.  
  1157. /**
  1158.  * Check if the current post has any of given category.
  1159.  *
  1160.  * @since 3.1.0
  1161.  *
  1162.  * @param string|int|array $tag Optional. The category name/term_id/slug or array of them to check for.
  1163.  * @param int|object $post Optional. Post to check instead of the current post.
  1164.  * @return bool True if the current post has any of the given categories (or any category, if no category specified).
  1165.  */
  1166. function has_category( $category = '', $post = null ) {
  1167.     return has_term( $category, 'category', $post );
  1168. }
  1169.  
  1170. /**
  1171.  * Check if the current post has any of given tags.
  1172.  *
  1173.  * The given tags are checked against the post's tags' term_ids, names and slugs.
  1174.  * Tags given as integers will only be checked against the post's tags' term_ids.
  1175.  * If no tags are given, determines if post has any tags.
  1176.  *
  1177.  * 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)
  1178.  * Prior to v2.7, this function could only be used in the WordPress Loop.
  1179.  * As of 2.7, the function can be used anywhere if it is provided a post ID or post object.
  1180.  *
  1181.  * @since 2.6.0
  1182.  *
  1183.  * @param string|int|array $tag Optional. The tag name/term_id/slug or array of them to check for.
  1184.  * @param int|object $post Optional. Post to check instead of the current post. (since 2.7.0)
  1185.  * @return bool True if the current post has any of the given tags (or any tag, if no tag specified).
  1186.  */
  1187. function has_tag( $tag = '', $post = null ) {
  1188.     return has_term( $tag, 'post_tag', $post );
  1189. }
  1190.  
  1191. /**
  1192.  * Check if the current post has any of given terms.
  1193.  *
  1194.  * The given terms are checked against the post's terms' term_ids, names and slugs.
  1195.  * Terms given as integers will only be checked against the post's terms' term_ids.
  1196.  * If no terms are given, determines if post has any terms.
  1197.  *
  1198.  * @since 3.1.0
  1199.  *
  1200.  * @param string|int|array $term Optional. The term name/term_id/slug or array of them to check for.
  1201.  * @param string $taxonomy Taxonomy name
  1202.  * @param int|object $post Optional. Post to check instead of the current post.
  1203.  * @return bool True if the current post has any of the given tags (or any tag, if no tag specified).
  1204.  */
  1205. function has_term( $term = '', $taxonomy = '', $post = null ) {
  1206.     $post = get_post($post);
  1207.  
  1208.     if ( !$post )
  1209.         return false;
  1210.  
  1211.     $r = is_object_in_term( $post->ID, $taxonomy, $term );
  1212.     if ( is_wp_error( $r ) )
  1213.         return false;
  1214.  
  1215.     return $r;
  1216. }
  1217.  
  1218. ?>
  1219.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement