Make WordPress Core


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

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

File:
1 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 .= ")";
Note: See TracChangeset for help on using the changeset viewer.