Use full hierarchy when resolving category URIs. fixes #1787 Props: ringmaster Owen
git-svn-id: https://develop.svn.wordpress.org/trunk@2968 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
471552766e
commit
b127cd82af
|
@ -434,20 +434,32 @@ class WP_Query {
|
||||||
|
|
||||||
// Category stuff for nice URIs
|
// Category stuff for nice URIs
|
||||||
|
|
||||||
|
global $cache_categories;
|
||||||
if ('' != $q['category_name']) {
|
if ('' != $q['category_name']) {
|
||||||
if (stristr($q['category_name'],'/')) {
|
$cat_paths = '/' . trim(urldecode($q['category_name']), '/');
|
||||||
$q['category_name'] = explode('/',$q['category_name']);
|
$q['category_name'] = sanitize_title(basename($cat_paths));
|
||||||
if ($q['category_name'][count($q['category_name'])-1]) {
|
$cat_paths = explode('/', $cat_paths);
|
||||||
$q['category_name'] = $q['category_name'][count($q['category_name'])-1]; // no trailing slash
|
foreach($cat_paths as $pathdir)
|
||||||
} else {
|
$cat_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir);
|
||||||
$q['category_name'] = $q['category_name'][count($q['category_name'])-2]; // there was a trailling slash
|
|
||||||
|
$q['cat'] = array_reduce(
|
||||||
|
$cache_categories,
|
||||||
|
create_function('$a, $b', 'return ($b->fullpath == "'.$cat_path.'") ? $b->cat_ID : $a;'),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
// If full path not found, look for last dir as category ignoring parent
|
||||||
|
if($q['cat'] == 0) {
|
||||||
|
$q['cat'] = array_reduce(
|
||||||
|
$cache_categories,
|
||||||
|
create_function('$a, $b', 'return ($b->category_nicename == "'.$q['category_name'].'") ? $b->cat_ID : $a;'),
|
||||||
|
0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
$q['category_name'] = sanitize_title($q['category_name']);
|
|
||||||
$tables = ", $wpdb->post2cat, $wpdb->categories";
|
$tables = ", $wpdb->post2cat, $wpdb->categories";
|
||||||
$join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) LEFT JOIN $wpdb->categories ON ($wpdb->post2cat.category_id = $wpdb->categories.cat_ID) ";
|
$join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) LEFT JOIN $wpdb->categories ON ($wpdb->post2cat.category_id = $wpdb->categories.cat_ID) ";
|
||||||
$whichcat = " AND (category_nicename = '" . $q['category_name'] . "'";
|
$whichcat = " AND (category_id = '" . $q['cat'] . "'";
|
||||||
$q['cat'] = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '" . $q['category_name'] . "'");
|
|
||||||
$whichcat .= get_category_children($q['cat'], " OR category_id = ");
|
$whichcat .= get_category_children($q['cat'], " OR category_id = ");
|
||||||
$whichcat .= ")";
|
$whichcat .= ")";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1321,6 +1321,15 @@ function update_category_cache() {
|
||||||
if ( $dogs = $wpdb->get_results("SELECT * FROM $wpdb->categories") ):
|
if ( $dogs = $wpdb->get_results("SELECT * FROM $wpdb->categories") ):
|
||||||
foreach ($dogs as $catt)
|
foreach ($dogs as $catt)
|
||||||
$cache_categories[$catt->cat_ID] = $catt;
|
$cache_categories[$catt->cat_ID] = $catt;
|
||||||
|
|
||||||
|
foreach ($cache_categories as $catt) {
|
||||||
|
$curcat = $catt->cat_ID;
|
||||||
|
$cache_categories[$catt->cat_ID]->fullpath = '/' . $cache_categories[$catt->cat_ID]->category_nicename;
|
||||||
|
while ($cache_categories[$curcat]->category_parent != 0) {
|
||||||
|
$curcat = $cache_categories[$curcat]->category_parent;
|
||||||
|
$cache_categories[$catt->cat_ID]->fullpath = '/' . $cache_categories[$curcat]->category_nicename . $cache_categories[$catt->cat_ID]->fullpath;
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
else :
|
else :
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue