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: https://develop.svn.wordpress.org/trunk@5590 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
c342666830
commit
1a08c04371
|
@ -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) {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue