Make WordPress Core

Changeset 5530


Ignore:
Timestamp:
05/23/2007 06:59:12 PM (17 years ago)
Author:
ryan
Message:

Convert category queries and list cats to taxonomy. see #4189

Location:
trunk/wp-includes
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/bookmark-template.php

    r5444 r5530  
    168168
    169169    $cat = get_category($cat_id);
    170     return $cat->cat_name;
     170    return $cat->name;
    171171}
    172172
     
    230230
    231231            // Display the category name
    232             echo '  <li id="linkcat-' . $cat->cat_ID . '" class="linkcat"><h2>' . $cat->cat_name . "</h2>\n\t<ul>\n";
     232            echo '  <li id="linkcat-' . $cat->term_id . '" class="linkcat"><h2>' . $cat->name . "</h2>\n\t<ul>\n";
    233233            // Call get_links() with all the appropriate params
    234             get_links($cat->cat_ID, '<li>', "</li>", "\n", true, 'name', false);
     234            get_links($cat->term_id, '<li>', "</li>", "\n", true, 'name', false);
    235235
    236236            // Close the last category
     
    337337
    338338        foreach ( (array) $cats as $cat ) {
    339             $params = array_merge($r, array('category'=>$cat->cat_ID));
     339            $params = array_merge($r, array('category'=>$cat->term_id));
    340340            $bookmarks = get_bookmarks($params);
    341341            if ( empty($bookmarks) )
    342342                continue;
    343             $output .= str_replace(array('%id', '%class'), array("linkcat-$cat->cat_ID", $class), $category_before);
    344             $catname = apply_filters( "link_category", $cat->cat_name );
     343            $output .= str_replace(array('%id', '%class'), array("linkcat-$cat->term_id", $class), $category_before);
     344            $catname = apply_filters( "link_category", $cat->name );
    345345            $output .= "$title_before$catname$title_after\n\t<ul>\n";
    346346            $output .= _walk_bookmarks($bookmarks, $r);
  • trunk/wp-includes/category-template.php

    r5529 r5530  
    66
    77    $chain = '';
    8 
     8    // TODO: consult hierarchy
    99    $cat_ids = get_all_category_ids();
    1010    foreach ( $cat_ids as $cat_id ) {
    11         if ( $cat_id == $id)
     11        if ( $cat_id == $id )
    1212            continue;
    1313
  • trunk/wp-includes/classes.php

    r5444 r5530  
    558558class Walker_Category extends Walker {
    559559    var $tree_type = 'category';
    560     var $db_fields = array ('parent' => 'category_parent', 'id' => 'cat_ID'); //TODO: decouple this
     560    var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
    561561
    562562    function start_lvl($output, $depth, $args) {
     
    581581        extract($args);
    582582
    583         $cat_name = attribute_escape( $category->cat_name);
     583        $cat_name = attribute_escape( $category->name);
    584584        $cat_name = apply_filters( 'list_cats', $cat_name, $category );
    585         $link = '<a href="' . get_category_link( $category->cat_ID ) . '" ';
    586         if ( $use_desc_for_title == 0 || empty($category->category_description) )
     585        $link = '<a href="' . get_category_link( $category->term_id ) . '" ';
     586        if ( $use_desc_for_title == 0 || empty($category->description) )
    587587            $link .= 'title="' . sprintf(__( 'View all posts filed under %s' ), $cat_name) . '"';
    588588        else
    589             $link .= 'title="' . attribute_escape( apply_filters( 'category_description', $category->category_description, $category )) . '"';
     589            $link .= 'title="' . attribute_escape( apply_filters( 'category_description', $category->description, $category )) . '"';
    590590        $link .= '>';
    591591        $link .= $cat_name . '</a>';
     
    597597                $link .= '(';
    598598
    599             $link .= '<a href="' . get_category_rss_link( 0, $category->cat_ID, $category->category_nicename ) . '"';
     599            $link .= '<a href="' . get_category_rss_link( 0, $category->term_id, $category->slug ) . '"';
    600600
    601601            if ( empty($feed) )
     
    620620
    621621        if ( isset($show_count) && $show_count )
    622             $link .= ' (' . intval($category->category_count) . ')';
     622            $link .= ' (' . intval($category->count) . ')';
    623623
    624624        if ( isset($show_date) && $show_date ) {
     
    631631        if ( 'list' == $args['style'] ) {
    632632            $output .= "\t<li";
    633             if ( $current_category && ($category->cat_ID == $current_category) )
     633            if ( $current_category && ($category->term_id == $current_category) )
    634634                $output .=  ' class="current-cat"';
    635             elseif ( $_current_category && ($category->cat_ID == $_current_category->category_parent) )
     635            elseif ( $_current_category && ($category->term_id == $_current_category->parent) )
    636636                $output .=  ' class="current-cat-parent"';
    637637            $output .= ">$link\n";
     
    655655class Walker_CategoryDropdown extends Walker {
    656656    var $tree_type = 'category';
    657     var $db_fields = array ('parent' => 'category_parent', 'id' => 'cat_ID'); //TODO: decouple this
     657    var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
    658658
    659659    function start_el($output, $category, $depth, $args) {
    660660        $pad = str_repeat('&nbsp;', $depth * 3);
    661661
    662         $cat_name = apply_filters('list_cats', $category->cat_name, $category);
    663         $output .= "\t<option value=\"".$category->cat_ID."\"";
    664         if ( $category->cat_ID == $args['selected'] )
     662        $cat_name = apply_filters('list_cats', $category->name, $category);
     663        $output .= "\t<option value=\"".$category->term_id."\"";
     664        if ( $category->term_id == $args['selected'] )
    665665            $output .= ' selected="selected"';
    666666        $output .= '>';
    667667        $output .= $pad.$cat_name;
    668668        if ( $args['show_count'] )
    669             $output .= '&nbsp;&nbsp;('. $category->category_count .')';
     669            $output .= '&nbsp;&nbsp;('. $category->count .')';
    670670        if ( $args['show_last_update'] ) {
    671671            $format = 'Y-m-d';
  • trunk/wp-includes/query.php

    r5521 r5530  
    7777    $cat_obj = $wp_query->get_queried_object();
    7878
    79     if ( $category == $cat_obj->cat_ID )
    80         return true;
    81     else if ( $category == $cat_obj->cat_name )
    82         return true;
    83     elseif ( $category == $cat_obj->category_nicename )
     79    if ( $category == $cat_obj->term_id )
     80        return true;
     81    else if ( $category == $cat_obj->name )
     82        return true;
     83    elseif ( $category == $cat_obj->slug )
    8484        return true;
    8585
     
    843843            $q['cat'] = ''.urldecode($q['cat']).'';
    844844            $q['cat'] = addslashes_gpc($q['cat']);
    845             $join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) ";
     845            $join = " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) ";
    846846            $cat_array = preg_split('/[,\s]+/', $q['cat']);
    847847            $in_cats = $out_cats = $out_posts = '';
     
    858858            $out_cats = substr($out_cats, 0, -2);
    859859            if ( strlen($in_cats) > 0 )
    860                 $in_cats = " AND $wpdb->post2cat.category_id IN ($in_cats) AND rel_type = 'category' ";
     860                $in_cats = " AND $wpdb->term_taxonomy.term_id IN ({$q['cat']}) ";
    861861            if ( strlen($out_cats) > 0 ) {
     862                // TODO
    862863                $ids = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE $wpdb->post2cat.category_id IN ($out_cats)");
    863864                if ( is_array($ids) && count($ids > 0) ) {
     
    871872                    $out_cats = '';
    872873            }
    873             $whichcat = $in_cats . $out_cats;
     874            $whichcat = " AND $wpdb->term_taxonomy.taxonomy = 'category' ";
     875            $whichcat .= $in_cats . $out_cats;
    874876            $groupby = "{$wpdb->posts}.ID";
    875877        }
     
    883885
    884886            $q['tag_id'] = $reqtag;
    885             // TODO: use term taxonomy
    886             $tables = ", $wpdb->post2cat, $wpdb->categories";
    887887            $join = " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) ";
    888888            $whichcat = " AND $wpdb->term_taxonomy.term_id IN ({$q['tag_id']}) AND $wpdb->term_taxonomy.taxonomy = 'post_tag' ";
     
    909909
    910910            if ( !empty($reqcat) )
    911                 $reqcat = $reqcat->cat_ID;
     911                $reqcat = $reqcat->term_id;
    912912            else
    913913                $reqcat = 0;
     
    915915            $q['cat'] = $reqcat;
    916916
    917             $tables = ", $wpdb->post2cat, $wpdb->categories";
    918             $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) ";
    919             $whichcat = " AND category_id IN ({$q['cat']}, ";
     917            $join = " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) ";
     918            $whichcat = " AND $wpdb->term_taxonomy.taxonomy = 'category' ";
     919            $whichcat .= "AND $wpdb->term_taxonomy.term_id IN ({$q['cat']}, ";
    920920            $whichcat .= get_category_children($q['cat'], '', ', ');
    921921            $whichcat = substr($whichcat, 0, -2);
    922             $whichcat .= ") AND rel_type = 'category'";
     922            $whichcat .= ")";
    923923            $groupby = "{$wpdb->posts}.ID";
    924924        }
Note: See TracChangeset for help on using the changeset viewer.