Make WordPress Core

Changeset 1385


Ignore:
Timestamp:
06/04/2004 02:36:46 AM (20 years ago)
Author:
rboren
Message:

Add %category% support to get_permalink.

Location:
trunk/wp-includes
Files:
2 edited

Legend:

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

    r1375 r1385  
    11<?php
    22
    3 function get_the_category() {
     3function get_the_category($id = false) {
    44    global $post, $wpdb, $category_cache;
    5     if ($category_cache[$post->ID]) {
    6         return $category_cache[$post->ID];
     5
     6    if (! $id) {
     7        $id = $post->ID;
     8    }
     9
     10    if ($category_cache[$id]) {
     11        return $category_cache[$id];
    712    } else {
    813        $categories = $wpdb->get_results("
    914            SELECT category_id, cat_name, category_nicename, category_description, category_parent
    1015            FROM  $wpdb->categories, $wpdb->post2cat
    11             WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = $post->ID
     16            WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = $id
    1217            ");
    1318   
  • trunk/wp-includes/template-functions-links.php

    r1384 r1385  
    3939        '%second%',
    4040        '%postname%',
    41         '%post_id%'
     41        '%post_id%',
     42        '%category%'
    4243    );
    43     if (!$id) {
    44         if ('' != get_settings('permalink_structure')) {
    45         $unixtime = strtotime($post->post_date);
    46             $rewritereplace = array(
    47                 date('Y', $unixtime),
    48                 date('m', $unixtime),
    49                 date('d', $unixtime),
    50                 date('H', $unixtime),
    51                 date('i', $unixtime),
    52                 date('s', $unixtime),
    53                 $post->post_name,
    54                 $post->ID
    55             );
    56             return get_settings('home') . str_replace($rewritecode, $rewritereplace, get_settings('permalink_structure'));
    57         } else { // if they're not using the fancy permalink option
    58             return get_settings('home') . '/' . get_settings('blogfilename').$querystring_start.'p'.$querystring_equal.$post->ID;
    59         }
    60     } else { // if an ID is given
    61         $idpost = $wpdb->get_row("SELECT post_date, post_name FROM $wpdb->posts WHERE ID = $id");
    62         if ('' != get_settings('permalink_structure')) {
     44
     45    if ($id) {
     46        $idpost = $wpdb->get_row("SELECT ID, post_date, post_name FROM $wpdb->posts WHERE ID = $id");
     47    } else {
     48        $idpost = $post;
     49    }
     50       
     51    if ('' != get_settings('permalink_structure')) {
    6352        $unixtime = strtotime($idpost->post_date);
    64             $rewritereplace = array(
    65                 date('Y', $unixtime),
    66                 date('m', $unixtime),
    67                 date('d', $unixtime),
    68                 date('H', $unixtime),
    69                 date('i', $unixtime),
    70                 date('s', $unixtime),
    71                 $idpost->post_name,
    72                 $id
    73             );
    74             return get_settings('home') . str_replace($rewritecode, $rewritereplace, get_settings('permalink_structure'));
    75         } else {
    76             return get_settings('home') . '/' . get_settings('blogfilename').$querystring_start.'p'.$querystring_equal.$id;
    77         }
     53
     54        $cats = get_the_category($idpost->ID);
     55        $category = $cats[0]->category_nicename;
     56
     57        $rewritereplace = array(
     58                                date('Y', $unixtime),
     59                                date('m', $unixtime),
     60                                date('d', $unixtime),
     61                                date('H', $unixtime),
     62                                date('i', $unixtime),
     63                                date('s', $unixtime),
     64                                $idpost->post_name,
     65                                $idpost->ID,
     66                                $category
     67                                );
     68        return get_settings('home') . str_replace($rewritecode, $rewritereplace, get_settings('permalink_structure'));
     69    } else { // if they're not using the fancy permalink option
     70        return get_settings('home') . '/' . get_settings('blogfilename').$querystring_start.'p'.$querystring_equal.$idpost->ID;
    7871    }
    7972}
Note: See TracChangeset for help on using the changeset viewer.