WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/27/2005 08:45:01 PM (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-post.php

    r2435 r2478  
    2727
    2828function get_the_title($id = 0) {
    29     global $post, $wpdb;
    30    
    31     if ( 0 != $id ) {
    32         $id_post = $wpdb->get_row("SELECT post_title, post_password FROM $wpdb->posts WHERE ID = $id");
    33         $title = $id_post->post_title;
    34         if (!empty($id_post->post_password))
    35             $title = sprintf(__('Protected: %s'), $title);
    36     }
    37     else {
    38         $title = $post->post_title;
    39         if (!empty($post->post_password))
    40             $title = sprintf(__('Protected: %s'), $title);
    41     }
     29    $post = &get_post($id);
     30
     31    $title = $post->post_title;
     32    if (!empty($post->post_password))
     33        $title = sprintf(__('Protected: %s'), $title);
     34
    4235    return $title;
    4336}
    4437
    4538function get_the_guid( $id = 0 ) {
    46     global $post, $wpdb;
    47     $guid = $post->guid;
    48 
    49     if ( 0 != $id )
    50         $guid = $wpdb->get_var("SELECT guid FROM $wpdb->posts WHERE ID = $id");
    51     $guid = apply_filters('get_the_guid', $guid);
    52     return $guid;
     39    $post = &get_post($id);
     40   
     41    return apply_filters('get_the_guid', $post->guid);
    5342}
    5443
    5544function the_guid( $id = 0 ) {
    56     echo get_the_guid();
     45    echo get_the_guid($id);
    5746}
    5847
     
    262251//
    263252
    264 function get_pages($args = '') {
     253function &get_pages($args = '') {
    265254    global $wpdb, $cache_pages;
    266255
     
    281270    }
    282271
    283     $dates = ",UNIX_TIMESTAMP(post_modified) AS time_modified";
    284     $dates .= ",UNIX_TIMESTAMP(post_date) AS time_created";
    285    
    286272    $post_parent = '';
    287273    if ($r['child_of']) {
     
    289275    }
    290276   
    291     $pages = $wpdb->get_results("SELECT " .
    292                                                             "ID, post_title, post_name, post_parent " .
    293                                                             "$dates " .
     277    $pages = $wpdb->get_results("SELECT * " .
    294278                                                            "FROM $wpdb->posts " .
    295279                                                            "WHERE post_status = 'static' " .
     
    298282                                                            "ORDER BY " . $r['sort_column'] . " " . $r['sort_order']);
    299283
    300     // Update page cache.
    301     if (count($pages)) {
    302         foreach($pages as $page) {
    303             $cache_pages[$page->ID] = $page;
    304         }
    305     }
     284    // Update cache.
     285    update_post_cache($pages);
    306286
    307287    if ( empty($pages) )
     
    320300
    321301    // Query pages.
    322     $pages = get_pages($args);
     302    $pages = & get_pages($args);
    323303    if ( $pages ) :
    324304
     
    339319        if (! empty($r['show_date'])) {
    340320            if ('modified' == $r['show_date'])
    341                 $page_tree[$page->ID]['ts'] = $page->time_modified;
     321                $page_tree[$page->ID]['ts'] = $page->post_modified;
    342322            else
    343                 $page_tree[$page->ID]['ts'] = $page->time_created;
     323                $page_tree[$page->ID]['ts'] = $page->post_date;
    344324        }
    345325
     
    384364            if(isset($args['date_format']))
    385365                $format = $args['date_format'];
    386             echo " " . gmdate($format,$cur_page['ts']);
     366            echo " " . mysql2date($format,$cur_page['ts']);
    387367        }
    388368        echo "\n";
Note: See TracChangeset for help on using the changeset viewer.