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:
parent
007e5937cf
commit
b0ffd98c95
|
@ -69,15 +69,24 @@ function get_the_category($id = false) {
|
|||
$categories = get_object_terms($id, 'category');
|
||||
|
||||
if ( !empty($categories) )
|
||||
usort($categories, '_get_the_category_usort');
|
||||
usort($categories, '_usort_terms_by_name');
|
||||
else
|
||||
$categories = array();
|
||||
|
||||
return $categories;
|
||||
}
|
||||
|
||||
function _get_the_category_usort($a, $b) {
|
||||
return strcmp($a->category_name, $b->category_name);
|
||||
function _usort_terms_by_name($a, $b) {
|
||||
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) {
|
||||
|
|
|
@ -73,6 +73,8 @@ function get_permalink($id = 0) {
|
|||
$category = '';
|
||||
if (strpos($permalink, '%category%') !== false) {
|
||||
$cats = get_the_category($post->ID);
|
||||
if ( $cats )
|
||||
usort($cats, '_usort_terms_by_ID'); // order by ID
|
||||
$category = $cats[0]->slug;
|
||||
if ( $parent=$cats[0]->parent )
|
||||
$category = get_category_parents($parent, FALSE, '/', TRUE) . $category;
|
||||
|
|
Loading…
Reference in New Issue