switch to term_id and name for category sorting. see #4189. sort by term_id for category permalinks, by name for get_the_category(). fixes #4335 for trunk. Props Erik Barzeski for the find.

git-svn-id: http://svn.automattic.com/wordpress/trunk@5590 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
markjaquith 2007-05-29 04:54:45 +00:00
parent 007e5937cf
commit b0ffd98c95
2 changed files with 14 additions and 3 deletions

View File

@ -69,15 +69,24 @@ function get_the_category($id = false) {
$categories = get_object_terms($id, 'category'); $categories = get_object_terms($id, 'category');
if ( !empty($categories) ) if ( !empty($categories) )
usort($categories, '_get_the_category_usort'); usort($categories, '_usort_terms_by_name');
else else
$categories = array(); $categories = array();
return $categories; return $categories;
} }
function _get_the_category_usort($a, $b) { function _usort_terms_by_name($a, $b) {
return strcmp($a->category_name, $b->category_name); return strcmp($a->name, $b->name);
}
function _usort_terms_by_ID($a, $b) {
if ( $a->term_id > $b->term_id )
return 1;
elseif ( $a->term_id < $b->term_id )
return -1;
else
return 0;
} }
function get_the_category_by_ID($cat_ID) { function get_the_category_by_ID($cat_ID) {

View File

@ -73,6 +73,8 @@ function get_permalink($id = 0) {
$category = ''; $category = '';
if (strpos($permalink, '%category%') !== false) { if (strpos($permalink, '%category%') !== false) {
$cats = get_the_category($post->ID); $cats = get_the_category($post->ID);
if ( $cats )
usort($cats, '_usort_terms_by_ID'); // order by ID
$category = $cats[0]->slug; $category = $cats[0]->slug;
if ( $parent=$cats[0]->parent ) if ( $parent=$cats[0]->parent )
$category = get_category_parents($parent, FALSE, '/', TRUE) . $category; $category = get_category_parents($parent, FALSE, '/', TRUE) . $category;