Make WordPress Core

Ticket #36171: 36171.diff

File 36171.diff, 4.2 KB (added by boonebgorges, 9 years ago)
  • src/wp-includes/category-template.php

    diff --git src/wp-includes/category-template.php src/wp-includes/category-template.php
    index 35d6c82..388cf84 100644
    function get_the_category_by_ID( $cat_ID ) { 
    168168 * @param int $post_id Optional. Post ID to retrieve categories.
    169169 * @return string
    170170 */
    171 function get_the_category_list( $separator = '', $parents='', $post_id = false ) {
     171function get_the_category_list( $separator = '', $parents = '', $post_id = false ) {
    172172        global $wp_rewrite;
     173
    173174        if ( ! is_object_in_taxonomy( get_post_type( $post_id ), 'category' ) ) {
    174175                /** This filter is documented in wp-includes/category-template.php */
    175176                return apply_filters( 'the_category', '', $separator, $parents );
    function get_the_category_list( $separator = '', $parents='', $post_id = false ) 
    193194
    194195        $rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="category"';
    195196
     197        $links = array();
     198        foreach ( $categories as $category ) {
     199                /**
     200                 * Break the link for better link building
     201                 */
     202                $start_link = '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>';
     203                $end_link   = $category->name . '</a>';
     204
     205                /**
     206                 * Build the category links
     207                 */
     208                $the_link_list = '';
     209                switch ( strtolower( $parents ) ) {
     210                        case 'multiple':
     211                                $cat_parents   = $category->parent ? get_category_parents( $category->parent, true, $separator ) : '';
     212                                $the_link_list = $cat_parents . ' ' . $start_link . $end_link;
     213                                break;
     214                        case 'single':
     215                                $cat_parents   = $category->parent ? get_category_parents( $category->parent, false, $separator ) : '';
     216                                $the_link_list = $start_link . $cat_parents . $end_link;
     217                                break;
     218                        case '':
     219                        default:
     220                                $the_link_list = $start_link . $end_link;
     221                }
     222
     223                /**
     224                 * Filter the category links on category level.
     225                 *
     226                 * @since X.X.X
     227                 *
     228                 * @param string $the_link_list Post category link.
     229                 * @param object $category      The current category object
     230                 * @param $cat_parents          Link list of parents of the current category
     231                 */
     232                $links[] = apply_filters( 'the_category_list_links', $the_link_list, $category, $cat_parents );
     233        }
     234
    196235        $thelist = '';
    197         if ( '' == $separator ) {
     236        if ( '' === $separator ) {
    198237                $thelist .= '<ul class="post-categories">';
    199                 foreach ( $categories as $category ) {
    200                         $thelist .= "\n\t<li>";
    201                         switch ( strtolower( $parents ) ) {
    202                                 case 'multiple':
    203                                         if ( $category->parent )
    204                                                 $thelist .= get_category_parents( $category->parent, true, $separator );
    205                                         $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a></li>';
    206                                         break;
    207                                 case 'single':
    208                                         $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '"  ' . $rel . '>';
    209                                         if ( $category->parent )
    210                                                 $thelist .= get_category_parents( $category->parent, false, $separator );
    211                                         $thelist .= $category->name.'</a></li>';
    212                                         break;
    213                                 case '':
    214                                 default:
    215                                         $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a></li>';
    216                         }
    217                 }
     238                $thelist .= "\n\t<li>";
     239                $thelist .= implode( "</li>\n\t<li>", $links );
     240                $thelist .= '</li>';
    218241                $thelist .= '</ul>';
    219242        } else {
    220                 $i = 0;
    221                 foreach ( $categories as $category ) {
    222                         if ( 0 < $i )
    223                                 $thelist .= $separator;
    224                         switch ( strtolower( $parents ) ) {
    225                                 case 'multiple':
    226                                         if ( $category->parent )
    227                                                 $thelist .= get_category_parents( $category->parent, true, $separator );
    228                                         $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a>';
    229                                         break;
    230                                 case 'single':
    231                                         $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>';
    232                                         if ( $category->parent )
    233                                                 $thelist .= get_category_parents( $category->parent, false, $separator );
    234                                         $thelist .= "$category->name</a>";
    235                                         break;
    236                                 case '':
    237                                 default:
    238                                         $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a>';
    239                         }
    240                         ++$i;
    241                 }
     243                $thelist .= implode( $separator, $links );
    242244        }
    243245
    244246        /**