WordPress.org

Make WordPress Core

Ticket #4335: cat_id_order__branches_2.2.diff

File cat_id_order__branches_2.2.diff, 1.1 KB (added by markjaquith, 7 years ago)

Pick category-based post permalink by lowest category ID (patch for 2.2 branch)

  • wp-includes/link-template.php

     
    7777                $category = ''; 
    7878                if (strpos($permalink, '%category%') !== false) { 
    7979                        $cats = get_the_category($post->ID); 
     80                        if ( $cats ) 
     81                                usort($cats, '_get_the_category_usort_by_ID'); // order by ID 
    8082                        $category = $cats[0]->category_nicename; 
    8183                        if ( $parent=$cats[0]->category_parent ) 
    8284                                $category = get_category_parents($parent, FALSE, '/', TRUE) . $category; 
  • wp-includes/category-template.php

     
    8383        return strcmp($a->category_name, $b->category_name); 
    8484} 
    8585 
     86function _get_the_category_usort_by_ID($a, $b) { 
     87        if ( $a->cat_ID > $b->cat_ID ) 
     88                return 1; 
     89        elseif ( $a->cat_ID < $b->cat_ID ) 
     90                return -1; 
     91        else 
     92                return 0; 
     93} 
     94 
    8695function get_the_category_by_ID($cat_ID) { 
    8796        $cat_ID = (int) $cat_ID; 
    8897        $category = &get_category($cat_ID);