Changeset 34110 for trunk/src/wp-includes/category-template.php
- Timestamp:
- 09/14/2015 03:09:37 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/category-template.php
r33804 r34110 973 973 } 974 974 975 /**976 * Create HTML list of categories.977 *978 * @package WordPress979 * @since 2.1.0980 * @uses Walker981 */982 class Walker_Category extends Walker {983 /**984 * What the class handles.985 *986 * @see Walker::$tree_type987 * @since 2.1.0988 * @var string989 */990 public $tree_type = 'category';991 992 /**993 * Database fields to use.994 *995 * @see Walker::$db_fields996 * @since 2.1.0997 * @todo Decouple this998 * @var array999 */1000 public $db_fields = array ('parent' => 'parent', 'id' => 'term_id');1001 1002 /**1003 * Starts the list before the elements are added.1004 *1005 * @see Walker::start_lvl()1006 *1007 * @since 2.1.01008 *1009 * @param string $output Passed by reference. Used to append additional content.1010 * @param int $depth Depth of category. Used for tab indentation.1011 * @param array $args An array of arguments. Will only append content if style argument value is 'list'.1012 * @see wp_list_categories()1013 */1014 public function start_lvl( &$output, $depth = 0, $args = array() ) {1015 if ( 'list' != $args['style'] )1016 return;1017 1018 $indent = str_repeat("\t", $depth);1019 $output .= "$indent<ul class='children'>\n";1020 }1021 1022 /**1023 * Ends the list of after the elements are added.1024 *1025 * @see Walker::end_lvl()1026 *1027 * @since 2.1.01028 *1029 * @param string $output Passed by reference. Used to append additional content.1030 * @param int $depth Depth of category. Used for tab indentation.1031 * @param array $args An array of arguments. Will only append content if style argument value is 'list'.1032 * @wsee wp_list_categories()1033 */1034 public function end_lvl( &$output, $depth = 0, $args = array() ) {1035 if ( 'list' != $args['style'] )1036 return;1037 1038 $indent = str_repeat("\t", $depth);1039 $output .= "$indent</ul>\n";1040 }1041 1042 /**1043 * Start the element output.1044 *1045 * @see Walker::start_el()1046 *1047 * @since 2.1.01048 *1049 * @param string $output Passed by reference. Used to append additional content.1050 * @param object $category Category data object.1051 * @param int $depth Depth of category in reference to parents. Default 0.1052 * @param array $args An array of arguments. @see wp_list_categories()1053 * @param int $id ID of the current category.1054 */1055 public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {1056 /** This filter is documented in wp-includes/category-template.php */1057 $cat_name = apply_filters(1058 'list_cats',1059 esc_attr( $category->name ),1060 $category1061 );1062 1063 // Don't generate an element if the category name is empty.1064 if ( ! $cat_name ) {1065 return;1066 }1067 1068 $link = '<a href="' . esc_url( get_term_link( $category ) ) . '" ';1069 if ( $args['use_desc_for_title'] && ! empty( $category->description ) ) {1070 /**1071 * Filter the category description for display.1072 *1073 * @since 1.2.01074 *1075 * @param string $description Category description.1076 * @param object $category Category object.1077 */1078 $link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"';1079 }1080 1081 $link .= '>';1082 $link .= $cat_name . '</a>';1083 1084 if ( ! empty( $args['feed_image'] ) || ! empty( $args['feed'] ) ) {1085 $link .= ' ';1086 1087 if ( empty( $args['feed_image'] ) ) {1088 $link .= '(';1089 }1090 1091 $link .= '<a href="' . esc_url( get_term_feed_link( $category->term_id, $category->taxonomy, $args['feed_type'] ) ) . '"';1092 1093 if ( empty( $args['feed'] ) ) {1094 $alt = ' alt="' . sprintf(__( 'Feed for all posts filed under %s' ), $cat_name ) . '"';1095 } else {1096 $alt = ' alt="' . $args['feed'] . '"';1097 $name = $args['feed'];1098 $link .= empty( $args['title'] ) ? '' : $args['title'];1099 }1100 1101 $link .= '>';1102 1103 if ( empty( $args['feed_image'] ) ) {1104 $link .= $name;1105 } else {1106 $link .= "<img src='" . $args['feed_image'] . "'$alt" . ' />';1107 }1108 $link .= '</a>';1109 1110 if ( empty( $args['feed_image'] ) ) {1111 $link .= ')';1112 }1113 }1114 1115 if ( ! empty( $args['show_count'] ) ) {1116 $link .= ' (' . number_format_i18n( $category->count ) . ')';1117 }1118 if ( 'list' == $args['style'] ) {1119 $output .= "\t<li";1120 $css_classes = array(1121 'cat-item',1122 'cat-item-' . $category->term_id,1123 );1124 1125 if ( ! empty( $args['current_category'] ) ) {1126 // 'current_category' can be an array, so we use `get_terms()`.1127 $_current_terms = get_terms( $category->taxonomy, array(1128 'include' => $args['current_category'],1129 'hide_empty' => false,1130 ) );1131 1132 foreach ( $_current_terms as $_current_term ) {1133 if ( $category->term_id == $_current_term->term_id ) {1134 $css_classes[] = 'current-cat';1135 } elseif ( $category->term_id == $_current_term->parent ) {1136 $css_classes[] = 'current-cat-parent';1137 }1138 }1139 }1140 1141 /**1142 * Filter the list of CSS classes to include with each category in the list.1143 *1144 * @since 4.2.01145 *1146 * @see wp_list_categories()1147 *1148 * @param array $css_classes An array of CSS classes to be applied to each list item.1149 * @param object $category Category data object.1150 * @param int $depth Depth of page, used for padding.1151 * @param array $args An array of wp_list_categories() arguments.1152 */1153 $css_classes = implode( ' ', apply_filters( 'category_css_class', $css_classes, $category, $depth, $args ) );1154 1155 $output .= ' class="' . $css_classes . '"';1156 $output .= ">$link\n";1157 } else {1158 $output .= "\t$link<br />\n";1159 }1160 }1161 1162 /**1163 * Ends the element output, if needed.1164 *1165 * @see Walker::end_el()1166 *1167 * @since 2.1.01168 *1169 * @param string $output Passed by reference. Used to append additional content.1170 * @param object $page Not used.1171 * @param int $depth Depth of category. Not used.1172 * @param array $args An array of arguments. Only uses 'list' for whether should append to output. @see wp_list_categories()1173 */1174 public function end_el( &$output, $page, $depth = 0, $args = array() ) {1175 if ( 'list' != $args['style'] )1176 return;1177 1178 $output .= "</li>\n";1179 }1180 1181 }1182 1183 /**1184 * Create HTML dropdown list of Categories.1185 *1186 * @package WordPress1187 * @since 2.1.01188 * @uses Walker1189 */1190 class Walker_CategoryDropdown extends Walker {1191 /**1192 * @see Walker::$tree_type1193 * @since 2.1.01194 * @var string1195 */1196 public $tree_type = 'category';1197 1198 /**1199 * @see Walker::$db_fields1200 * @since 2.1.01201 * @todo Decouple this1202 * @var array1203 */1204 public $db_fields = array ('parent' => 'parent', 'id' => 'term_id');1205 1206 /**1207 * Start the element output.1208 *1209 * @see Walker::start_el()1210 * @since 2.1.01211 *1212 * @param string $output Passed by reference. Used to append additional content.1213 * @param object $category Category data object.1214 * @param int $depth Depth of category. Used for padding.1215 * @param array $args Uses 'selected', 'show_count', and 'value_field' keys, if they exist.1216 * See {@see wp_dropdown_categories()}.1217 */1218 public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {1219 $pad = str_repeat(' ', $depth * 3);1220 1221 /** This filter is documented in wp-includes/category-template.php */1222 $cat_name = apply_filters( 'list_cats', $category->name, $category );1223 1224 if ( isset( $args['value_field'] ) && isset( $category->{$args['value_field']} ) ) {1225 $value_field = $args['value_field'];1226 } else {1227 $value_field = 'term_id';1228 }1229 1230 $output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $category->{$value_field} ) . "\"";1231 1232 // Type-juggling causes false matches, so we force everything to a string.1233 if ( (string) $category->{$value_field} === (string) $args['selected'] )1234 $output .= ' selected="selected"';1235 $output .= '>';1236 $output .= $pad.$cat_name;1237 if ( $args['show_count'] )1238 $output .= ' ('. number_format_i18n( $category->count ) .')';1239 $output .= "</option>\n";1240 }1241 }1242 1243 975 // 1244 976 // Tags
Note: See TracChangeset
for help on using the changeset viewer.