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

git-svn-id: http://svn.automattic.com/wordpress/trunk@5530 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2007-05-23 18:59:12 +00:00
parent 0e05576999
commit b00beb3027
4 changed files with 35 additions and 35 deletions

View File

@ -167,7 +167,7 @@ function get_linkcatname($id = 0) {
$cat_id = (int) $cats[0]; // Take the first cat.
$cat = get_category($cat_id);
return $cat->cat_name;
return $cat->name;
}
/** function links_popup_script()
@ -229,9 +229,9 @@ function get_links_list($order = 'name', $hide_if_empty = 'obsolete') {
// Handle each category.
// Display the category name
echo ' <li id="linkcat-' . $cat->cat_ID . '" class="linkcat"><h2>' . $cat->cat_name . "</h2>\n\t<ul>\n";
echo ' <li id="linkcat-' . $cat->term_id . '" class="linkcat"><h2>' . $cat->name . "</h2>\n\t<ul>\n";
// Call get_links() with all the appropriate params
get_links($cat->cat_ID, '<li>', "</li>", "\n", true, 'name', false);
get_links($cat->term_id, '<li>', "</li>", "\n", true, 'name', false);
// Close the last category
echo "\n\t</ul>\n</li>\n";
@ -336,12 +336,12 @@ function wp_list_bookmarks($args = '') {
$cats = get_categories("type=link&category_name=$category_name&include=$category&orderby=$category_orderby&order=$category_order&hierarchical=0");
foreach ( (array) $cats as $cat ) {
$params = array_merge($r, array('category'=>$cat->cat_ID));
$params = array_merge($r, array('category'=>$cat->term_id));
$bookmarks = get_bookmarks($params);
if ( empty($bookmarks) )
continue;
$output .= str_replace(array('%id', '%class'), array("linkcat-$cat->cat_ID", $class), $category_before);
$catname = apply_filters( "link_category", $cat->cat_name );
$output .= str_replace(array('%id', '%class'), array("linkcat-$cat->term_id", $class), $category_before);
$catname = apply_filters( "link_category", $cat->name );
$output .= "$title_before$catname$title_after\n\t<ul>\n";
$output .= _walk_bookmarks($bookmarks, $r);
$output .= "\n\t</ul>\n$category_after\n";

View File

@ -5,10 +5,10 @@ function get_category_children($id, $before = '/', $after = '') {
return '';
$chain = '';
// TODO: consult hierarchy
$cat_ids = get_all_category_ids();
foreach ( $cat_ids as $cat_id ) {
if ( $cat_id == $id)
if ( $cat_id == $id )
continue;
$category = get_category($cat_id);

View File

@ -557,7 +557,7 @@ class Walker_PageDropdown extends Walker {
class Walker_Category extends Walker {
var $tree_type = 'category';
var $db_fields = array ('parent' => 'category_parent', 'id' => 'cat_ID'); //TODO: decouple this
var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
function start_lvl($output, $depth, $args) {
if ( 'list' != $args['style'] )
@ -580,13 +580,13 @@ class Walker_Category extends Walker {
function start_el($output, $category, $depth, $args) {
extract($args);
$cat_name = attribute_escape( $category->cat_name);
$cat_name = attribute_escape( $category->name);
$cat_name = apply_filters( 'list_cats', $cat_name, $category );
$link = '<a href="' . get_category_link( $category->cat_ID ) . '" ';
if ( $use_desc_for_title == 0 || empty($category->category_description) )
$link = '<a href="' . get_category_link( $category->term_id ) . '" ';
if ( $use_desc_for_title == 0 || empty($category->description) )
$link .= 'title="' . sprintf(__( 'View all posts filed under %s' ), $cat_name) . '"';
else
$link .= 'title="' . attribute_escape( apply_filters( 'category_description', $category->category_description, $category )) . '"';
$link .= 'title="' . attribute_escape( apply_filters( 'category_description', $category->description, $category )) . '"';
$link .= '>';
$link .= $cat_name . '</a>';
@ -596,7 +596,7 @@ class Walker_Category extends Walker {
if ( empty($feed_image) )
$link .= '(';
$link .= '<a href="' . get_category_rss_link( 0, $category->cat_ID, $category->category_nicename ) . '"';
$link .= '<a href="' . get_category_rss_link( 0, $category->term_id, $category->slug ) . '"';
if ( empty($feed) )
$alt = ' alt="' . sprintf(__( 'Feed for all posts filed under %s' ), $cat_name ) . '"';
@ -619,7 +619,7 @@ class Walker_Category extends Walker {
}
if ( isset($show_count) && $show_count )
$link .= ' (' . intval($category->category_count) . ')';
$link .= ' (' . intval($category->count) . ')';
if ( isset($show_date) && $show_date ) {
$link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp);
@ -630,9 +630,9 @@ class Walker_Category extends Walker {
if ( 'list' == $args['style'] ) {
$output .= "\t<li";
if ( $current_category && ($category->cat_ID == $current_category) )
if ( $current_category && ($category->term_id == $current_category) )
$output .= ' class="current-cat"';
elseif ( $_current_category && ($category->cat_ID == $_current_category->category_parent) )
elseif ( $_current_category && ($category->term_id == $_current_category->parent) )
$output .= ' class="current-cat-parent"';
$output .= ">$link\n";
} else {
@ -654,19 +654,19 @@ class Walker_Category extends Walker {
class Walker_CategoryDropdown extends Walker {
var $tree_type = 'category';
var $db_fields = array ('parent' => 'category_parent', 'id' => 'cat_ID'); //TODO: decouple this
var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
function start_el($output, $category, $depth, $args) {
$pad = str_repeat('&nbsp;', $depth * 3);
$cat_name = apply_filters('list_cats', $category->cat_name, $category);
$output .= "\t<option value=\"".$category->cat_ID."\"";
if ( $category->cat_ID == $args['selected'] )
$cat_name = apply_filters('list_cats', $category->name, $category);
$output .= "\t<option value=\"".$category->term_id."\"";
if ( $category->term_id == $args['selected'] )
$output .= ' selected="selected"';
$output .= '>';
$output .= $pad.$cat_name;
if ( $args['show_count'] )
$output .= '&nbsp;&nbsp;('. $category->category_count .')';
$output .= '&nbsp;&nbsp;('. $category->count .')';
if ( $args['show_last_update'] ) {
$format = 'Y-m-d';
$output .= '&nbsp;&nbsp;' . gmdate($format, $category->last_update_timestamp);

View File

@ -76,11 +76,11 @@ function is_category ($category = '') {
$cat_obj = $wp_query->get_queried_object();
if ( $category == $cat_obj->cat_ID )
if ( $category == $cat_obj->term_id )
return true;
else if ( $category == $cat_obj->cat_name )
else if ( $category == $cat_obj->name )
return true;
elseif ( $category == $cat_obj->category_nicename )
elseif ( $category == $cat_obj->slug )
return true;
return false;
@ -842,7 +842,7 @@ class WP_Query {
} else {
$q['cat'] = ''.urldecode($q['cat']).'';
$q['cat'] = addslashes_gpc($q['cat']);
$join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) ";
$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) ";
$cat_array = preg_split('/[,\s]+/', $q['cat']);
$in_cats = $out_cats = $out_posts = '';
foreach ( $cat_array as $cat ) {
@ -857,8 +857,9 @@ class WP_Query {
$in_cats = substr($in_cats, 0, -2);
$out_cats = substr($out_cats, 0, -2);
if ( strlen($in_cats) > 0 )
$in_cats = " AND $wpdb->post2cat.category_id IN ($in_cats) AND rel_type = 'category' ";
$in_cats = " AND $wpdb->term_taxonomy.term_id IN ({$q['cat']}) ";
if ( strlen($out_cats) > 0 ) {
// TODO
$ids = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE $wpdb->post2cat.category_id IN ($out_cats)");
if ( is_array($ids) && count($ids > 0) ) {
foreach ( $ids as $id )
@ -870,7 +871,8 @@ class WP_Query {
else
$out_cats = '';
}
$whichcat = $in_cats . $out_cats;
$whichcat = " AND $wpdb->term_taxonomy.taxonomy = 'category' ";
$whichcat .= $in_cats . $out_cats;
$groupby = "{$wpdb->posts}.ID";
}
@ -882,8 +884,6 @@ class WP_Query {
$reqtag = 0;
$q['tag_id'] = $reqtag;
// TODO: use term taxonomy
$tables = ", $wpdb->post2cat, $wpdb->categories";
$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) ";
$whichcat = " AND $wpdb->term_taxonomy.term_id IN ({$q['tag_id']}) AND $wpdb->term_taxonomy.taxonomy = 'post_tag' ";
$groupby = "{$wpdb->posts}.ID";
@ -908,18 +908,18 @@ class WP_Query {
$reqcat = get_category_by_path($q['category_name'], false);
if ( !empty($reqcat) )
$reqcat = $reqcat->cat_ID;
$reqcat = $reqcat->term_id;
else
$reqcat = 0;
$q['cat'] = $reqcat;
$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) ";
$whichcat = " AND category_id IN ({$q['cat']}, ";
$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) ";
$whichcat = " AND $wpdb->term_taxonomy.taxonomy = 'category' ";
$whichcat .= "AND $wpdb->term_taxonomy.term_id IN ({$q['cat']}, ";
$whichcat .= get_category_children($q['cat'], '', ', ');
$whichcat = substr($whichcat, 0, -2);
$whichcat .= ") AND rel_type = 'category'";
$whichcat .= ")";
$groupby = "{$wpdb->posts}.ID";
}