Changeset 16100 for trunk/wp-includes/category-template.php
- Timestamp:
- 10/30/2010 02:06:08 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/category-template.php
r15855 r16100 744 744 } 745 745 746 /** 747 * Create HTML list of categories. 748 * 749 * @package WordPress 750 * @since 2.1.0 751 * @uses Walker 752 */ 753 class Walker_Category extends Walker { 754 /** 755 * @see Walker::$tree_type 756 * @since 2.1.0 757 * @var string 758 */ 759 var $tree_type = 'category'; 760 761 /** 762 * @see Walker::$db_fields 763 * @since 2.1.0 764 * @todo Decouple this 765 * @var array 766 */ 767 var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); 768 769 /** 770 * @see Walker::start_lvl() 771 * @since 2.1.0 772 * 773 * @param string $output Passed by reference. Used to append additional content. 774 * @param int $depth Depth of category. Used for tab indentation. 775 * @param array $args Will only append content if style argument value is 'list'. 776 */ 777 function start_lvl(&$output, $depth, $args) { 778 if ( 'list' != $args['style'] ) 779 return; 780 781 $indent = str_repeat("\t", $depth); 782 $output .= "$indent<ul class='children'>\n"; 783 } 784 785 /** 786 * @see Walker::end_lvl() 787 * @since 2.1.0 788 * 789 * @param string $output Passed by reference. Used to append additional content. 790 * @param int $depth Depth of category. Used for tab indentation. 791 * @param array $args Will only append content if style argument value is 'list'. 792 */ 793 function end_lvl(&$output, $depth, $args) { 794 if ( 'list' != $args['style'] ) 795 return; 796 797 $indent = str_repeat("\t", $depth); 798 $output .= "$indent</ul>\n"; 799 } 800 801 /** 802 * @see Walker::start_el() 803 * @since 2.1.0 804 * 805 * @param string $output Passed by reference. Used to append additional content. 806 * @param object $category Category data object. 807 * @param int $depth Depth of category in reference to parents. 808 * @param array $args 809 */ 810 function start_el(&$output, $category, $depth, $args) { 811 extract($args); 812 813 $cat_name = esc_attr( $category->name ); 814 $cat_name = apply_filters( 'list_cats', $cat_name, $category ); 815 $link = '<a href="' . esc_attr( get_term_link($category) ) . '" '; 816 if ( $use_desc_for_title == 0 || empty($category->description) ) 817 $link .= 'title="' . sprintf(__( 'View all posts filed under %s' ), $cat_name) . '"'; 818 else 819 $link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"'; 820 $link .= '>'; 821 $link .= $cat_name . '</a>'; 822 823 if ( !empty($feed_image) || !empty($feed) ) { 824 $link .= ' '; 825 826 if ( empty($feed_image) ) 827 $link .= '('; 828 829 $link .= '<a href="' . get_term_feed_link( $category->term_id, $category->taxonomy, $feed_type ) . '"'; 830 831 if ( empty($feed) ) { 832 $alt = ' alt="' . sprintf(__( 'Feed for all posts filed under %s' ), $cat_name ) . '"'; 833 } else { 834 $title = ' title="' . $feed . '"'; 835 $alt = ' alt="' . $feed . '"'; 836 $name = $feed; 837 $link .= $title; 838 } 839 840 $link .= '>'; 841 842 if ( empty($feed_image) ) 843 $link .= $name; 844 else 845 $link .= "<img src='$feed_image'$alt$title" . ' />'; 846 847 $link .= '</a>'; 848 849 if ( empty($feed_image) ) 850 $link .= ')'; 851 } 852 853 if ( !empty($show_count) ) 854 $link .= ' (' . intval($category->count) . ')'; 855 856 if ( !empty($show_date) ) 857 $link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp); 858 859 if ( 'list' == $args['style'] ) { 860 $output .= "\t<li"; 861 $class = 'cat-item cat-item-' . $category->term_id; 862 if ( !empty($current_category) ) { 863 $_current_category = get_term( $current_category, $category->taxonomy ); 864 if ( $category->term_id == $current_category ) 865 $class .= ' current-cat'; 866 elseif ( $category->term_id == $_current_category->parent ) 867 $class .= ' current-cat-parent'; 868 } 869 $output .= ' class="' . $class . '"'; 870 $output .= ">$link\n"; 871 } else { 872 $output .= "\t$link<br />\n"; 873 } 874 } 875 876 /** 877 * @see Walker::end_el() 878 * @since 2.1.0 879 * 880 * @param string $output Passed by reference. Used to append additional content. 881 * @param object $page Not used. 882 * @param int $depth Depth of category. Not used. 883 * @param array $args Only uses 'list' for whether should append to output. 884 */ 885 function end_el(&$output, $page, $depth, $args) { 886 if ( 'list' != $args['style'] ) 887 return; 888 889 $output .= "</li>\n"; 890 } 891 892 } 893 894 /** 895 * Create HTML dropdown list of Categories. 896 * 897 * @package WordPress 898 * @since 2.1.0 899 * @uses Walker 900 */ 901 class Walker_CategoryDropdown extends Walker { 902 /** 903 * @see Walker::$tree_type 904 * @since 2.1.0 905 * @var string 906 */ 907 var $tree_type = 'category'; 908 909 /** 910 * @see Walker::$db_fields 911 * @since 2.1.0 912 * @todo Decouple this 913 * @var array 914 */ 915 var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); 916 917 /** 918 * @see Walker::start_el() 919 * @since 2.1.0 920 * 921 * @param string $output Passed by reference. Used to append additional content. 922 * @param object $category Category data object. 923 * @param int $depth Depth of category. Used for padding. 924 * @param array $args Uses 'selected', 'show_count', and 'show_last_update' keys, if they exist. 925 */ 926 function start_el(&$output, $category, $depth, $args) { 927 $pad = str_repeat(' ', $depth * 3); 928 929 $cat_name = apply_filters('list_cats', $category->name, $category); 930 $output .= "\t<option class=\"level-$depth\" value=\"".$category->term_id."\""; 931 if ( $category->term_id == $args['selected'] ) 932 $output .= ' selected="selected"'; 933 $output .= '>'; 934 $output .= $pad.$cat_name; 935 if ( $args['show_count'] ) 936 $output .= ' ('. $category->count .')'; 937 if ( $args['show_last_update'] ) { 938 $format = 'Y-m-d'; 939 $output .= ' ' . gmdate($format, $category->last_update_timestamp); 940 } 941 $output .= "</option>\n"; 942 } 943 } 944 746 945 // 747 946 // Tags
Note: See TracChangeset
for help on using the changeset viewer.