mirror of
git://develop.git.wordpress.org/
synced 2025-01-18 05:18:42 +01:00
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');
|
||||
|
||||
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…
x
Reference in New Issue
Block a user