Make WordPress Core

Changeset 2968


Ignore:
Timestamp:
10/28/2005 01:14:57 AM (21 years ago)
Author:
ryan
Message:

Use full hierarchy when resolving category URIs. fixes #1787 Props: ringmaster Owen

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/classes.php

    r2961 r2968  
    435435                // Category stuff for nice URIs
    436436
     437                global $cache_categories;
    437438                if ('' != $q['category_name']) {
    438                         if (stristr($q['category_name'],'/')) {
    439                                 $q['category_name'] = explode('/',$q['category_name']);
    440                                 if ($q['category_name'][count($q['category_name'])-1]) {
    441                                         $q['category_name'] = $q['category_name'][count($q['category_name'])-1]; // no trailing slash
    442                                 } else {
    443                                         $q['category_name'] = $q['category_name'][count($q['category_name'])-2]; // there was a trailling slash
    444                                 }
    445                         }
    446                         $q['category_name'] = sanitize_title($q['category_name']);
     439                        $cat_paths = '/' . trim(urldecode($q['category_name']), '/');
     440                        $q['category_name'] = sanitize_title(basename($cat_paths));
     441                        $cat_paths = explode('/', $cat_paths);
     442                        foreach($cat_paths as $pathdir)
     443                                $cat_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir);
     444
     445                        $q['cat'] = array_reduce(
     446                                $cache_categories,
     447                                create_function('$a, $b', 'return ($b->fullpath == "'.$cat_path.'") ? $b->cat_ID : $a;'),
     448                                0
     449                        );
     450
     451                        // If full path not found, look for last dir as category ignoring parent
     452                        if($q['cat'] == 0) {
     453                                $q['cat'] = array_reduce(
     454                                        $cache_categories,
     455                                        create_function('$a, $b', 'return ($b->category_nicename == "'.$q['category_name'].'") ? $b->cat_ID : $a;'),
     456                                        0
     457                                );
     458                        }
     459                       
    447460                        $tables = ", $wpdb->post2cat, $wpdb->categories";
    448461                        $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) ";
    449                         $whichcat = " AND (category_nicename = '" . $q['category_name'] . "'";
    450                         $q['cat'] = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '" . $q['category_name'] . "'");
     462                        $whichcat = " AND (category_id = '" . $q['cat'] . "'";
    451463                        $whichcat .= get_category_children($q['cat'], " OR category_id = ");
    452464                        $whichcat .= ")";
  • trunk/wp-includes/functions.php

    r2958 r2968  
    13201320        global $cache_categories, $wpdb;
    13211321        if ( $dogs = $wpdb->get_results("SELECT * FROM $wpdb->categories") ):
    1322         foreach ($dogs as $catt)
    1323                 $cache_categories[$catt->cat_ID] = $catt;
     1322                foreach ($dogs as $catt)
     1323                        $cache_categories[$catt->cat_ID] = $catt;
     1324
     1325                foreach ($cache_categories as $catt) {
     1326                        $curcat = $catt->cat_ID;
     1327                        $cache_categories[$catt->cat_ID]->fullpath = '/' . $cache_categories[$catt->cat_ID]->category_nicename;
     1328                        while ($cache_categories[$curcat]->category_parent != 0) {
     1329                                $curcat = $cache_categories[$curcat]->category_parent;
     1330                                $cache_categories[$catt->cat_ID]->fullpath = '/' . $cache_categories[$curcat]->category_nicename . $cache_categories[$catt->cat_ID]->fullpath;
     1331                        }
     1332                }
    13241333                return true;
    13251334        else :
Note: See TracChangeset for help on using the changeset viewer.