Ticket #1787: heir_cats.diff
| File heir_cats.diff, 3.0 KB (added by ringmaster, 7 years ago) |
|---|
-
wp-includes/classes.php
420 420 421 421 // Category stuff for nice URIs 422 422 423 global $cache_categories; 423 424 if ('' != $q['category_name']) { 424 if (stristr($q['category_name'],'/')) { 425 $q['category_name'] = explode('/',$q['category_name']); 426 if ($q['category_name'][count($q['category_name'])-1]) { 427 $q['category_name'] = $q['category_name'][count($q['category_name'])-1]; // no trailing slash 428 } else { 429 $q['category_name'] = $q['category_name'][count($q['category_name'])-2]; // there was a trailling slash 430 } 425 $cat_paths = '/' . trim(urldecode($q['category_name']), '/'); 426 $q['category_name'] = sanitize_title(basename($cat_paths)); 427 $cat_paths = explode('/', $cat_paths); 428 foreach($cat_paths as $pathdir) $cat_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir); 429 $q['cat'] = array_reduce( 430 $cache_categories, 431 create_function('$a, $b', 'return ($b->fullpath == "'.$cat_path.'") ? $b->cat_ID : $a;'), 432 0 433 ); 434 // If full path not found, look for last dir as category ignoring parent 435 if($q['cat'] == 0) { 436 $q['cat'] = array_reduce( 437 $cache_categories, 438 create_function('$a, $b', 'return ($b->category_nicename == "'.$q['category_name'].'") ? $b->cat_ID : $a;'), 439 0 440 ); 431 441 } 432 $q['category_name'] = sanitize_title($q['category_name']);442 433 443 $tables = ", $wpdb->post2cat, $wpdb->categories"; 434 444 $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) "; 435 445 $whichcat = " AND (category_nicename = '" . $q['category_name'] . "'"; 436 $q['cat'] = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '" . $q['category_name'] . "'");437 446 $whichcat .= get_category_children($q['cat'], " OR category_id = "); 438 447 $whichcat .= ")"; 439 448 } -
wp-includes/functions.php
1304 1304 function update_category_cache() { 1305 1305 global $cache_categories, $wpdb; 1306 1306 if($dogs = $wpdb->get_results("SELECT * FROM $wpdb->categories")): 1307 foreach ($dogs as $catt) 1308 $cache_categories[$catt->cat_ID] = $catt; 1307 foreach ($dogs as $catt) $cache_categories[$catt->cat_ID] = $catt; 1308 foreach ($cache_categories as $catt) { 1309 $curcat = $catt->cat_ID; 1310 $cache_categories[$catt->cat_ID]->fullpath = '/' . $cache_categories[$catt->cat_ID]->category_nicename; 1311 while ($cache_categories[$curcat]->category_parent != 0) { 1312 $curcat = $cache_categories[$curcat]->category_parent; 1313 $cache_categories[$catt->cat_ID]->fullpath = '/' . $cache_categories[$curcat]->category_nicename . $cache_categories[$catt->cat_ID]->fullpath; 1314 } 1315 } 1309 1316 return true; 1310 1317 else : 1311 1318 return false;
