WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/27/05 20:45:01 (13 years ago)
Author:
ryan
Message:

Cacheing cleanup. Introduce get_post() and get_category(). http://mosquito.wordpress.org/view.php?id=1157

File:
1 edited

Legend:

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

    r2450 r2478  
    22 
    33function get_the_category($id = false) { 
    4     global $post, $wpdb, $category_cache; 
     4    global $post, $category_cache; 
    55 
    66    if ( !$id ) 
    77        $id = $post->ID; 
    88 
    9     if ( $category_cache[$id] ) { 
    10         $categories = $category_cache[$id]; 
    11     } else { 
    12         $categories = $wpdb->get_results(" 
    13         SELECT category_id, cat_name, category_nicename, category_description, category_parent 
    14         FROM  $wpdb->categories, $wpdb->post2cat 
    15         WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$id' 
    16         "); 
    17     } 
     9    if ( ! isset($category_cache[$id]) ) 
     10        update_post_category_cache($id); 
     11 
     12    $categories = $category_cache[$id]; 
    1813 
    1914    if (!empty($categories)) 
     
    2621 
    2722function get_category_link($category_id) { 
    28     global $wpdb, $wp_rewrite, $querystring_start, $querystring_equal, $cache_categories; 
     23    global $wp_rewrite; 
    2924    $catlink = $wp_rewrite->get_category_permastruct(); 
    3025 
     
    3328        $catlink = $file . '?cat=' . $category_id; 
    3429    } else { 
    35         if ($cache_categories[$category_id]->category_nicename) 
    36             $category_nicename = $cache_categories[$category_id]->category_nicename; 
    37         else 
    38             $category_nicename = $wpdb->get_var('SELECT category_nicename FROM ' . $wpdb->categories . ' WHERE cat_ID=' . $category_id); 
    39  
    40         if ($parent = $cache_categories[$category_id]->category_parent)  
     30        $category = &get_category($category_id); 
     31        $category_nicename = $category->category_nicename; 
     32 
     33        if ($parent = $category->category_parent)  
    4134            $category_nicename = get_category_parents($parent, false, '/', true) . $category_nicename . '/'; 
    4235 
     
    109102 
    110103function get_the_category_by_ID($cat_ID) { 
    111     global $cache_categories, $wpdb; 
    112     if ( !$cache_categories[$cat_ID] ) { 
    113         $cat_name = $wpdb->get_var("SELECT cat_name FROM $wpdb->categories WHERE cat_ID = '$cat_ID'"); 
    114         $cache_categories[$cat_ID]->cat_name = $cat_name; 
    115     } else { 
    116         $cat_name = $cache_categories[$cat_ID]->cat_name; 
    117     } 
    118     return($cat_name); 
     104    $category = &get_category($cat_ID); 
     105    return $category->cat_name; 
    119106} 
    120107 
    121108function get_category_parents($id, $link = FALSE, $separator = '/', $nicename = FALSE){ 
    122     global $cache_categories; 
    123109    $chain = ''; 
    124     $parent = $cache_categories[$id]; 
     110        $parent = &get_category($id); 
    125111    if ($nicename) { 
    126112        $name = $parent->category_nicename; 
     
    176162 
    177163function category_description($category = 0) { 
    178     global $cat, $wpdb, $cache_categories; 
     164    global $cat; 
    179165    if (!$category) $category = $cat; 
    180     $category_description = $cache_categories[$category]->category_description; 
    181     $category_description = apply_filters('category_description', $category_description, $category); 
    182     return $category_description; 
     166        $category = & get_category($category); 
     167    return apply_filters('category_description', $category->category_description, $category->cat_ID); 
    183168} 
    184169 
Note: See TracChangeset for help on using the changeset viewer.