Add %category% support to get_permalink.

git-svn-id: http://svn.automattic.com/wordpress/trunk@1385 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
rboren 2004-06-04 02:36:46 +00:00
parent b3f30a2877
commit 12dea3832c
2 changed files with 37 additions and 39 deletions

View File

@ -1,14 +1,19 @@
<?php <?php
function get_the_category() { function get_the_category($id = false) {
global $post, $wpdb, $category_cache; global $post, $wpdb, $category_cache;
if ($category_cache[$post->ID]) {
return $category_cache[$post->ID]; if (! $id) {
$id = $post->ID;
}
if ($category_cache[$id]) {
return $category_cache[$id];
} else { } else {
$categories = $wpdb->get_results(" $categories = $wpdb->get_results("
SELECT category_id, cat_name, category_nicename, category_description, category_parent SELECT category_id, cat_name, category_nicename, category_description, category_parent
FROM $wpdb->categories, $wpdb->post2cat FROM $wpdb->categories, $wpdb->post2cat
WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = $post->ID WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = $id
"); ");
return $categories; return $categories;

View File

@ -38,43 +38,36 @@ function get_permalink($id=false) {
'%minute%', '%minute%',
'%second%', '%second%',
'%postname%', '%postname%',
'%post_id%' '%post_id%',
'%category%'
); );
if (!$id) {
if ('' != get_settings('permalink_structure')) { if ($id) {
$unixtime = strtotime($post->post_date); $idpost = $wpdb->get_row("SELECT ID, post_date, post_name FROM $wpdb->posts WHERE ID = $id");
$rewritereplace = array( } else {
date('Y', $unixtime), $idpost = $post;
date('m', $unixtime), }
date('d', $unixtime),
date('H', $unixtime), if ('' != get_settings('permalink_structure')) {
date('i', $unixtime),
date('s', $unixtime),
$post->post_name,
$post->ID
);
return get_settings('home') . str_replace($rewritecode, $rewritereplace, get_settings('permalink_structure'));
} else { // if they're not using the fancy permalink option
return get_settings('home') . '/' . get_settings('blogfilename').$querystring_start.'p'.$querystring_equal.$post->ID;
}
} else { // if an ID is given
$idpost = $wpdb->get_row("SELECT post_date, post_name FROM $wpdb->posts WHERE ID = $id");
if ('' != get_settings('permalink_structure')) {
$unixtime = strtotime($idpost->post_date); $unixtime = strtotime($idpost->post_date);
$rewritereplace = array(
date('Y', $unixtime), $cats = get_the_category($idpost->ID);
date('m', $unixtime), $category = $cats[0]->category_nicename;
date('d', $unixtime),
date('H', $unixtime), $rewritereplace = array(
date('i', $unixtime), date('Y', $unixtime),
date('s', $unixtime), date('m', $unixtime),
$idpost->post_name, date('d', $unixtime),
$id date('H', $unixtime),
); date('i', $unixtime),
return get_settings('home') . str_replace($rewritecode, $rewritereplace, get_settings('permalink_structure')); date('s', $unixtime),
} else { $idpost->post_name,
return get_settings('home') . '/' . get_settings('blogfilename').$querystring_start.'p'.$querystring_equal.$id; $idpost->ID,
} $category
);
return get_settings('home') . str_replace($rewritecode, $rewritereplace, get_settings('permalink_structure'));
} else { // if they're not using the fancy permalink option
return get_settings('home') . '/' . get_settings('blogfilename').$querystring_start.'p'.$querystring_equal.$idpost->ID;
} }
} }