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-links.php

    r2422 r2478  
    2323}
    2424
    25 function get_permalink($id = false) {
    26     global $post, $wpdb;
    27 
     25function get_permalink($id = 0) {
    2826    $rewritecode = array(
    2927        '%year%',
     
    4038    );
    4139
    42     if ($id) {
    43         $idpost = $wpdb->get_row("SELECT ID, post_date, post_name, post_status, post_author FROM $wpdb->posts WHERE ID = $id");
    44     } else {
    45         $idpost = $post;
     40    $post = & get_post($id);
     41    if ($post->post_status == 'static') {
     42        return get_page_link($post->ID);
    4643    }
    4744
    48     if ($idpost->post_status == 'static') {
    49         return get_page_link($idpost->ID);
    50     }
    51 
    5245    $permalink = get_settings('permalink_structure');
    5346
    5447    if ('' != $permalink) {
    55         $unixtime = strtotime($idpost->post_date);
     48        $unixtime = strtotime($post->post_date);
    5649
    5750        $category = '';
    5851        if (strstr($permalink, '%category%')) {
    59             $cats = get_the_category($idpost->ID);
     52            $cats = get_the_category($post->ID);
    6053            $category = $cats[0]->category_nicename;
    6154            if ($parent=$cats[0]->category_parent) $category = get_category_parents($parent, FALSE, '/', TRUE) . $category;
    6255        }
    6356
    64         $authordata = get_userdata($idpost->post_author);
     57        $authordata = get_userdata($post->post_author);
    6558        $author = $authordata->user_nicename;
    6659        $rewritereplace =
     
    7265            date('i', $unixtime),
    7366            date('s', $unixtime),
    74             $idpost->post_name,
    75             $idpost->ID,
     67            $post->post_name,
     68            $post->ID,
    7669            $category,
    7770            $author,
    78             $idpost->post_name,
     71            $post->post_name,
    7972        );
    80         return apply_filters('post_link', get_settings('home') . str_replace($rewritecode, $rewritereplace, $permalink), $idpost);
     73        return apply_filters('post_link', get_settings('home') . str_replace($rewritecode, $rewritereplace, $permalink), $post);
    8174    } else { // if they're not using the fancy permalink option
    82         $permalink = get_settings('home') . '/?p=' . $idpost->ID;
    83         return apply_filters('post_link', $permalink, $idpost);
     75        $permalink = get_settings('home') . '/?p=' . $post->ID;
     76        return apply_filters('post_link', $permalink, $post);
    8477    }
    8578}
Note: See TracChangeset for help on using the changeset viewer.