Ticket #29586: 29586.diff
| File 29586.diff, 5.8 KB (added by , 12 years ago) |
|---|
-
src/wp-includes/category-template.php
159 159 * @param int $post_id Optional. Post ID to retrieve categories. 160 160 * @return string 161 161 */ 162 function get_the_category_list( $separator = '', $parents='', $post_id = false ) { 163 global $wp_rewrite; 162 function get_the_category_list( $separator = 'list', $parents = '', $post_id = false ) { 164 163 if ( ! is_object_in_taxonomy( get_post_type( $post_id ), 'category' ) ) { 165 164 /** This filter is documented in wp-includes/category-template.php */ 166 165 return apply_filters( 'the_category', '', $separator, $parents ); 167 166 } 168 167 169 $categories = get_the_category( $post_id ); 170 if ( empty( $categories ) ) { 168 $list = get_the_term_list( $post_id, 'category', '', $separator, '', $parents ); 169 170 if ( empty( $list ) || is_wp_error( $list ) ) { 171 171 /** This filter is documented in wp-includes/category-template.php */ 172 172 return apply_filters( 'the_category', __( 'Uncategorized' ), $separator, $parents ); 173 173 } 174 174 175 $rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="category"';176 177 $thelist = '';178 if ( '' == $separator ) {179 $thelist .= '<ul class="post-categories">';180 foreach ( $categories as $category ) {181 $thelist .= "\n\t<li>";182 switch ( strtolower( $parents ) ) {183 case 'multiple':184 if ( $category->parent )185 $thelist .= get_category_parents( $category->parent, true, $separator );186 $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a></li>';187 break;188 case 'single':189 $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>';190 if ( $category->parent )191 $thelist .= get_category_parents( $category->parent, false, $separator );192 $thelist .= $category->name.'</a></li>';193 break;194 case '':195 default:196 $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a></li>';197 }198 }199 $thelist .= '</ul>';200 } else {201 $i = 0;202 foreach ( $categories as $category ) {203 if ( 0 < $i )204 $thelist .= $separator;205 switch ( strtolower( $parents ) ) {206 case 'multiple':207 if ( $category->parent )208 $thelist .= get_category_parents( $category->parent, true, $separator );209 $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a>';210 break;211 case 'single':212 $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>';213 if ( $category->parent )214 $thelist .= get_category_parents( $category->parent, false, $separator );215 $thelist .= "$category->name</a>";216 break;217 case '':218 default:219 $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a>';220 }221 ++$i;222 }223 }224 225 175 /** 226 176 * Filter the category or list of categories. 227 177 * … … 232 182 * @param string $parents How to display the category parents. Accepts 'multiple', 233 183 * 'single', or empty. 234 184 */ 235 return apply_filters( 'the_category', $ thelist, $separator, $parents );185 return apply_filters( 'the_category', $list, $separator, $parents ); 236 186 } 237 187 238 188 /** … … 1280 1230 * @param string $before Optional. Before list. 1281 1231 * @param string $sep Optional. Separate items using this. 1282 1232 * @param string $after Optional. After list. 1233 * @param string $parents Optional. How to display the parents. 1283 1234 * @return string|bool|WP_Error A list of terms on success, false if there are no terms, WP_Error on failure. 1284 1235 */ 1285 function get_the_term_list( $id, $taxonomy, $before = '', $sep = '', $after = '' ) { 1236 function get_the_term_list( $id, $taxonomy, $before = '', $sep = '', $after = '', $parents = '' ) { 1237 global $wp_rewrite; 1238 1286 1239 $terms = get_the_terms( $id, $taxonomy ); 1287 1240 1288 if ( is_wp_error( $terms ) ) 1241 if ( is_wp_error( $terms ) ) { 1289 1242 return $terms; 1243 } 1290 1244 1291 if ( empty( $terms ) ) 1245 if ( empty( $terms ) ) { 1292 1246 return false; 1247 } 1293 1248 1249 if ( 'category' == $taxonomy ) { 1250 $rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'category tag' : 'category'; 1251 } 1252 else { 1253 $rel = 'tag'; 1254 } 1255 1294 1256 foreach ( $terms as $term ) { 1295 1257 $link = get_term_link( $term, $taxonomy ); 1296 if ( is_wp_error( $link ) ) 1297 return $link; 1298 $term_links[] = '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>'; 1258 1259 if ( is_wp_error( $link ) ) { 1260 $link = ''; 1261 } 1262 1263 switch ( strtolower( $parents ) ) { 1264 case 'multiple': 1265 if ( $term->parent ) { 1266 $thelist .= get_category_parents( $term->parent, true, $separator ); 1267 } 1268 1269 $term_links[] = '<a href="' . esc_url( get_category_link( $term->term_id ) ) . '" rel="' . $rel . '">' . $category->name.'</a>'; 1270 break; 1271 case 'single': 1272 $thelist .= '<a href="' . esc_url( get_category_link( $term->term_id ) ) . '" rel="' . $rel . '">'; 1273 1274 if ( $category->parent ) { 1275 $thelist .= get_category_parents( $term->parent, false, $separator ); 1276 } 1277 1278 $thelist .= "$term->name</a>"; 1279 break; 1280 default: 1281 $term_links[] = '<a href="' . esc_url( $link ) . '" rel="' . $rel . '">' . $term->name.'</a>'; 1282 } 1299 1283 } 1300 1284 1301 1285 /** … … 1310 1294 */ 1311 1295 $term_links = apply_filters( "term_links-$taxonomy", $term_links ); 1312 1296 1313 return $before . join( $sep, $term_links ) . $after; 1297 $list = ''; 1298 if ( 'list' == $sep ) { 1299 $list = '<ul class="post-categories">'; 1300 1301 foreach ( $term_links as $term_link ) { 1302 $list .= "\n\t<li>" . $term_link . "</li>"; 1303 } 1304 1305 $list .= '</ul>'; 1306 } 1307 else { 1308 $list = join( $sep, $term_links ); 1309 } 1310 1311 1312 return $before . $list . $after; 1314 1313 } 1315 1314 1316 1315 /**
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)