Changeset 8975
- Timestamp:
- 09/25/2008 02:16:27 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/category-template.php
r8668 r8975 1 1 <?php 2 2 /** 3 * Category Template Tags and API. 4 * 5 * @package WordPress 6 * @subpackage Template 7 */ 8 9 /** 10 * Retrieve category children list separated before and after the term IDs. 11 * 12 * @since 1.2.0 13 * 14 * @param int $id Category ID to retrieve children. 15 * @param string $before Optional. Prepend before category term ID. 16 * @param string $after Optional, default is empty string. Append after category term ID. 17 * @param array $visited Optional. Category Term IDs that have already been added. 18 * @return string 19 */ 3 20 function get_category_children( $id, $before = '/', $after = '', $visited = array() ) { 4 21 if ( 0 == $id ) … … 6 23 7 24 $chain = ''; 8 / / TODO: consult hierarchy25 /** TODO: consult hierarchy */ 9 26 $cat_ids = get_all_category_ids(); 10 27 foreach ( (array) $cat_ids as $cat_id ) { … … 24 41 } 25 42 43 /** 44 * Retrieve category link URL. 45 * 46 * @since 1.0.0 47 * @uses apply_filters() Calls 'category_link' filter on category link and category ID. 48 * 49 * @param int $category_id Category ID. 50 * @return string 51 */ 26 52 function get_category_link( $category_id ) { 27 53 global $wp_rewrite; … … 46 72 } 47 73 48 function get_category_parents( $id, $link = FALSE, $separator = '/', $nicename = FALSE, $visited = array() ) { 74 /** 75 * Retrieve category parents with separator. 76 * 77 * @since 1.2.0 78 * 79 * @param int $id Category ID. 80 * @param bool $link Optional, default is false. Whether to format with link. 81 * @param string $separator Optional, default is '/'. How to separate categories. 82 * @param bool $nicename Optional, default is false. Whether to use nice name for display. 83 * @param array $visited Optional. Already linked to categories to prevent duplicates. 84 * @return string 85 */ 86 function get_category_parents( $id, $link = false, $separator = '/', $nicename = false, $visited = array() ) { 49 87 $chain = ''; 50 88 $parent = &get_category( $id ); … … 69 107 } 70 108 109 /** 110 * Retrieve post categories. 111 * 112 * @since 0.71 113 * @uses $post 114 * 115 * @param int $id Optional, default to current post ID. The post ID. 116 * @return array 117 */ 71 118 function get_the_category( $id = false ) { 72 119 global $post; … … 92 139 } 93 140 141 /** 142 * Sort categories by name. 143 * 144 * Used by usort() as a callback, should not be used directly. Can actually be 145 * used to sort any term object. 146 * 147 * @since 2.3.0 148 * @access private 149 * 150 * @param object $a 151 * @param object $b 152 * @return int 153 */ 94 154 function _usort_terms_by_name( $a, $b ) { 95 155 return strcmp( $a->name, $b->name ); 96 156 } 97 157 158 /** 159 * Sort categories by ID. 160 * 161 * Used by usort() as a callback, should not be used directly. Can actually be 162 * used to sort any term object. 163 * 164 * @since 2.3.0 165 * @access private 166 * 167 * @param object $a 168 * @param object $b 169 * @return int 170 */ 98 171 function _usort_terms_by_ID( $a, $b ) { 99 172 if ( $a->term_id > $b->term_id ) … … 105 178 } 106 179 180 /** 181 * Retrieve category name based on category ID. 182 * 183 * @since 0.71 184 * 185 * @param int $cat_ID Category ID. 186 * @return string Category name. 187 */ 107 188 function get_the_category_by_ID( $cat_ID ) { 108 189 $cat_ID = (int) $cat_ID; … … 113 194 } 114 195 196 /** 197 * Retrieve category list in either HTML list or custom format. 198 * 199 * @since 1.5.1 200 * 201 * @param string $separator Optional, default is empty string. Separator for between the categories. 202 * @param string $parents Optional. How to display the parents. 203 * @param int $post_id Optional. Post ID to retrieve categories. 204 * @return string 205 */ 115 206 function get_the_category_list( $separator = '', $parents='', $post_id = false ) { 116 207 global $wp_rewrite; … … 129 220 case 'multiple': 130 221 if ( $category->parent ) 131 $thelist .= get_category_parents( $category->parent, TRUE);222 $thelist .= get_category_parents( $category->parent, true ); 132 223 $thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . $rel . '>' . $category->name.'</a></li>'; 133 224 break; … … 135 226 $thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . $rel . '>'; 136 227 if ( $category->parent ) 137 $thelist .= get_category_parents( $category->parent, FALSE);228 $thelist .= get_category_parents( $category->parent, false ); 138 229 $thelist .= $category->name.'</a></li>'; 139 230 break; … … 152 243 case 'multiple': 153 244 if ( $category->parent ) 154 $thelist .= get_category_parents( $category->parent, TRUE);245 $thelist .= get_category_parents( $category->parent, true ); 155 246 $thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . $rel . '>' . $category->cat_name.'</a>'; 156 247 break; … … 158 249 $thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . $rel . '>'; 159 250 if ( $category->parent ) 160 $thelist .= get_category_parents( $category->parent, FALSE);251 $thelist .= get_category_parents( $category->parent, false ); 161 252 $thelist .= "$category->cat_name</a>"; 162 253 break; … … 171 262 } 172 263 173 /* 174 * in_category() - Checks whether the current post is within a particular category 175 * 176 * This function checks to see if the post is within the supplied category. The categoy 177 * can be specified by number or name and will be checked as a name first to allow for categories with numeric names. 178 * Note: Prior to v2.5 of WordPress category names where not supported. 264 /** 265 * Checks whether the current post is within a particular category. 266 * 267 * This function checks to see if the post is within the supplied category. The 268 * category can be specified by number or name and will be checked as a name 269 * first to allow for categories with numeric names. Note: Prior to v2.5 of 270 * WordPress category names were not supported. 179 271 * 180 272 * @since 1.2.0 181 273 * 182 * @param int|string $category 183 * @return bool true if the post is in the supplied category274 * @param int|string $category Category ID or category name. 275 * @return bool True, if the post is in the supplied category. 184 276 */ 185 function in_category( $category ) { // Check if the current post is in the given category277 function in_category( $category ) { 186 278 global $post; 187 279 … … 205 297 } 206 298 299 /** 300 * Display the category list for the post. 301 * 302 * @since 0.71 303 * 304 * @param string $separator Optional, default is empty string. Separator for between the categories. 305 * @param string $parents Optional. How to display the parents. 306 * @param int $post_id Optional. Post ID to retrieve categories. 307 */ 207 308 function the_category( $separator = '', $parents='', $post_id = false ) { 208 309 echo get_the_category_list( $separator, $parents, $post_id ); 209 310 } 210 311 312 /** 313 * Retrieve category description. 314 * 315 * @since 1.0.0 316 * 317 * @param int $category Optional. Category ID. Will use global category ID by default. 318 * @return string Category description, available. 319 */ 211 320 function category_description( $category = 0 ) { 212 321 global $cat; … … 217 326 } 218 327 328 /** 329 * Display or retrieve the HTML dropdown list of categories. 330 * 331 * The list of arguments is below: 332 * 'show_option_all' (string) - Text to display for showing all categories. 333 * 'show_option_none' (string) - Text to display for showing no categories. 334 * 'orderby' (string) default is 'ID' - What column to use for ordering the 335 * categories. 336 * 'order' (string) default is 'ASC' - What direction to order categories. 337 * 'show_last_update' (bool|int) default is 0 - See {@link get_categories()} 338 * 'show_count' (bool|int) default is 0 - Whether to show how many posts are 339 * in the category. 340 * 'hide_empty' (bool|int) default is 1 - Whether to hide categories that 341 * don't have any posts attached to them. 342 * 'child_of' (int) default is 0 - See {@link get_categories()}. 343 * 'exclude' (string) - See {@link get_categories()}. 344 * 'echo' (bool|int) default is 1 - Whether to display or retrieve content. 345 * 'depth' (int) - The max depth. 346 * 'tab_index' (int) - Tab index for select element. 347 * 'name' (string) - The name attribute value for selected element. 348 * 'class' (string) - The class attribute value for selected element. 349 * 'selected' (int) - Which category ID is selected. 350 * 351 * The 'hierarchical' argument, which is disabled by default, will override the 352 * depth argument, unless it is true. When the argument is false, it will 353 * display all of the categories. When it is enabled it will use the value in 354 * the 'depth' argument. 355 * 356 * @since 2.1.0 357 * 358 * @param string|array $args Optional. Override default arguments. 359 * @return string HTML content only if 'echo' argument is 0. 360 */ 219 361 function wp_dropdown_categories( $args = '' ) { 220 362 $defaults = array( … … 272 414 } 273 415 416 /** 417 * Display or retrieve the HTML list of categories. 418 * 419 * The list of arguments is below: 420 * 'show_option_all' (string) - Text to display for showing all categories. 421 * 'orderby' (string) default is 'ID' - What column to use for ordering the 422 * categories. 423 * 'order' (string) default is 'ASC' - What direction to order categories. 424 * 'show_last_update' (bool|int) default is 0 - See {@link 425 * walk_category_dropdown_tree()} 426 * 'show_count' (bool|int) default is 0 - Whether to show how many posts are 427 * in the category. 428 * 'hide_empty' (bool|int) default is 1 - Whether to hide categories that 429 * don't have any posts attached to them. 430 * 'use_desc_for_title' (bool|int) default is 1 - Whether to use the 431 * description instead of the category title. 432 * 'feed' - See {@link get_categories()}. 433 * 'feed_type' - See {@link get_categories()}. 434 * 'feed_image' - See {@link get_categories()}. 435 * 'child_of' (int) default is 0 - See {@link get_categories()}. 436 * 'exclude' (string) - See {@link get_categories()}. 437 * 'echo' (bool|int) default is 1 - Whether to display or retrieve content. 438 * 'current_category' (int) - See {@link get_categories()}. 439 * 'hierarchical' (bool) - See {@link get_categories()}. 440 * 'title_li' (string) - See {@link get_categories()}. 441 * 'depth' (int) - The max depth. 442 * 443 * @since 2.1.0 444 * 445 * @param string|array $args Optional. Override default arguments. 446 * @return string HTML content only if 'echo' argument is 0. 447 */ 274 448 function wp_list_categories( $args = '' ) { 275 449 $defaults = array( … … 338 512 } 339 513 514 /** 515 * Display tag cloud. 516 * 517 * The text size is set by the 'smallest' and 'largest' arguments, which will 518 * use the 'unit' argument value for the CSS text size unit. The 'format' 519 * argument can be 'flat' (default), 'list', or 'array'. The flat value for the 520 * 'format' argument will separate tags with spaces. The list value for the 521 * 'format' argument will format the tags in a UL HTML list. The array value for 522 * the 'format' argument will return in PHP array type format. 523 * 524 * The 'orderby' argument will accept 'name' or 'count' and defaults to 'name'. 525 * The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC'. 526 * 527 * The 'number' argument is how many tags to return. By default, the limit will 528 * be to return the top 45 tags in the tag cloud list. 529 * 530 * The 'single_text' and 'multiple_text' arguments are used for the link title 531 * for the tag link. If the tag only has one, it will use the text in the 532 * 'single_text' or if it has more than one it will use 'multiple_text' instead. 533 * 534 * The 'exclude' and 'include' arguments are used for the {@link get_tags()} 535 * function. Only one should be used, because only one will be used and the 536 * other ignored, if they are both set. 537 * 538 * @since 2.3.0 539 * 540 * @param array|string $args Optional. Override default arguments. 541 * @return array Generated tag cloud, only if no failures and 'array' is set for the 'format' argument. 542 */ 340 543 function wp_tag_cloud( $args = '' ) { 341 544 $defaults = array( … … 371 574 372 575 /** 373 * Generates a tag cloud (heatmap) from provided data 374 * 375 * TODO: Complete 376 * 377 * @since 2.6 378 * 379 * $tags = array of objects with the properties 'name', 'link', 'id', and 'count' 380 * $args['format'] = 'flat' => whitespace separated, 'list' => UL, 'array' => array() 381 * $args['orderby'] = 'name', 'count' 382 */ 576 * Generates a tag cloud (heatmap) from provided data. 577 * 578 * The text size is set by the 'smallest' and 'largest' arguments, which will 579 * use the 'unit' argument value for the CSS text size unit. The 'format' 580 * argument can be 'flat' (default), 'list', or 'array'. The flat value for the 581 * 'format' argument will separate tags with spaces. The list value for the 582 * 'format' argument will format the tags in a UL HTML list. The array value for 583 * the 'format' argument will return in PHP array type format. 584 * 585 * The 'orderby' argument will accept 'name' or 'count' and defaults to 'name'. 586 * The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC' or 587 * 'RAND'. 588 * 589 * The 'number' argument is how many tags to return. By default, the limit will 590 * be to return the entire tag cloud list. 591 * 592 * The 'single_text' and 'multiple_text' arguments are used for the link title 593 * for the tag link. If the tag only has one, it will use the text in the 594 * 'single_text' or if it has more than one it will use 'multiple_text' instead. 595 * 596 * @todo Complete functionality. 597 * @since 2.3.0 598 * 599 * @param array $tags List of tags. 600 * @param string|array $args Optional, override default arguments. 601 * @return string 602 */ 383 603 function wp_generate_tag_cloud( $tags, $args = '' ) { 384 604 global $wp_rewrite; … … 461 681 // 462 682 683 /** 684 * Retrieve HTML list content for category list. 685 * 686 * @uses Walker_Category to create HTML list content. 687 * @since 2.1.0 688 * @see Walker_Category::walk() for parameters and return description. 689 */ 463 690 function walk_category_tree() { 464 691 $walker = new Walker_Category; … … 467 694 } 468 695 696 /** 697 * Retrieve HTML dropdown (select) content for category list. 698 * 699 * @uses Walker_CategoryDropdown to create HTML dropdown content. 700 * @since 2.1.0 701 * @see Walker_CategoryDropdown::walk() for parameters and return description. 702 */ 469 703 function walk_category_dropdown_tree() { 470 704 $walker = new Walker_CategoryDropdown; … … 477 711 // 478 712 713 /** 714 * Retrieve the link to the tag. 715 * 716 * @since 2.3.0 717 * @uses apply_filters() Calls 'tag_link' with tag link and tag ID as parameters. 718 * 719 * @param int $tag_id Tag (term) ID. 720 * @return string 721 */ 479 722 function get_tag_link( $tag_id ) { 480 723 global $wp_rewrite; … … 496 739 } 497 740 741 /** 742 * Retrieve the tags for a post. 743 * 744 * @since 2.3.0 745 * @uses apply_filters() Calls 'get_the_tags' filter on the list of post tags. 746 * 747 * @param int $id Post ID. 748 * @return array 749 */ 498 750 function get_the_tags( $id = 0 ) { 499 751 return apply_filters( 'get_the_tags', get_the_terms( $id, 'post_tag' ) ); 500 752 } 501 753 754 /** 755 * Retrieve the tags for a post formatted as a string. 756 * 757 * @since 2.3.0 758 * @uses apply_filters() Calls 'the_tags' filter on string list of tags. 759 * 760 * @param string $before Optional. Before tags. 761 * @param string $sep Optional. Between tags. 762 * @param string $after Optional. After tags. 763 * @return string 764 */ 502 765 function get_the_tag_list( $before = '', $sep = '', $after = '' ) { 503 766 return apply_filters( 'the_tags', get_the_term_list( 0, 'post_tag', $before, $sep, $after ) ); 504 767 } 505 768 769 /** 770 * Retrieve the tags for a post. 771 * 772 * @since 2.3.0 773 * 774 * @param string $before Optional. Before list. 775 * @param string $sep Optional. Separate items using this. 776 * @param string $after Optional. After list. 777 * @return string 778 */ 506 779 function the_tags( $before = 'Tags: ', $sep = ', ', $after = '' ) { 507 780 return the_terms( 0, 'post_tag', $before, $sep, $after ); 508 781 } 509 782 783 /** 784 * Retrieve the terms of the taxonomy that are attached to the post. 785 * 786 * This function can only be used within the loop. 787 * 788 * @since 2.5.0 789 * 790 * @param int $id Post ID. Is not optional. 791 * @param string $taxonomy Taxonomy name. 792 * @return array|bool False on failure. Array of term objects on success. 793 */ 510 794 function get_the_terms( $id = 0, $taxonomy ) { 511 795 global $post; … … 529 813 } 530 814 815 /** 816 * Retrieve terms as a list with specified format. 817 * 818 * @since 2.5.0 819 * 820 * @param int $id Term ID. 821 * @param string $taxonomy Taxonomy name. 822 * @param string $before Optional. Before list. 823 * @param string $sep Optional. Separate items using this. 824 * @param string $after Optional. After list. 825 * @return string 826 */ 531 827 function get_the_term_list( $id = 0, $taxonomy, $before = '', $sep = '', $after = '' ) { 532 828 $terms = get_the_terms( $id, $taxonomy ); … … 550 846 } 551 847 848 /** 849 * Display the terms in a list. 850 * 851 * @since 2.5.0 852 * 853 * @param int $id Term ID. 854 * @param string $taxonomy Taxonomy name. 855 * @param string $before Optional. Before list. 856 * @param string $sep Optional. Separate items using this. 857 * @param string $after Optional. After list. 858 * @return null|bool False on WordPress error. Returns null when displaying. 859 */ 552 860 function the_terms( $id, $taxonomy, $before = '', $sep = '', $after = '' ) { 553 861 $return = get_the_term_list( $id, $taxonomy, $before, $sep, $after ); … … 559 867 560 868 /** 561 * Check if the current post has the given tag 562 * 563 * @package WordPress 564 * @since 2.6 869 * Check if the current post has the given tag. 870 * 871 * This function is only for use within the WordPress Loop. 872 * 873 * @since 2.6.0 565 874 * 566 875 * @uses wp_get_object_terms() Gets the tags. 567 876 * 568 * @param string|int|array $tag Optional. The tag name/id/slug or array of them to check for 569 * @return bool True if the current post has the given tag, or any tag, if no tag specified 877 * @param string|int|array $tag Optional. The tag name/id/slug or array of them to check for. 878 * @return bool True if the current post has the given tag, or any tag, if no tag specified. 570 879 */ 571 880 function has_tag( $tag = '' ) {
Note: See TracChangeset
for help on using the changeset viewer.