From 12dea3832c541e68c2e3382e3e8487662bb5b628 Mon Sep 17 00:00:00 2001 From: rboren Date: Fri, 4 Jun 2004 02:36:46 +0000 Subject: [PATCH] Add %category% support to get_permalink. git-svn-id: http://svn.automattic.com/wordpress/trunk@1385 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/template-functions-category.php | 13 +++-- wp-includes/template-functions-links.php | 63 +++++++++------------ 2 files changed, 37 insertions(+), 39 deletions(-) diff --git a/wp-includes/template-functions-category.php b/wp-includes/template-functions-category.php index a4bb9a4796..47e93c1fcc 100644 --- a/wp-includes/template-functions-category.php +++ b/wp-includes/template-functions-category.php @@ -1,14 +1,19 @@ ID]) { - return $category_cache[$post->ID]; + + if (! $id) { + $id = $post->ID; + } + + if ($category_cache[$id]) { + return $category_cache[$id]; } else { $categories = $wpdb->get_results(" SELECT category_id, cat_name, category_nicename, category_description, category_parent 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; diff --git a/wp-includes/template-functions-links.php b/wp-includes/template-functions-links.php index e2b0657838..a66d87a6ba 100644 --- a/wp-includes/template-functions-links.php +++ b/wp-includes/template-functions-links.php @@ -38,43 +38,36 @@ function get_permalink($id=false) { '%minute%', '%second%', '%postname%', - '%post_id%' + '%post_id%', + '%category%' ); - if (!$id) { - if ('' != get_settings('permalink_structure')) { - $unixtime = strtotime($post->post_date); - $rewritereplace = array( - date('Y', $unixtime), - date('m', $unixtime), - date('d', $unixtime), - date('H', $unixtime), - 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')) { + + if ($id) { + $idpost = $wpdb->get_row("SELECT ID, post_date, post_name FROM $wpdb->posts WHERE ID = $id"); + } else { + $idpost = $post; + } + + if ('' != get_settings('permalink_structure')) { $unixtime = strtotime($idpost->post_date); - $rewritereplace = array( - date('Y', $unixtime), - date('m', $unixtime), - date('d', $unixtime), - date('H', $unixtime), - date('i', $unixtime), - date('s', $unixtime), - $idpost->post_name, - $id - ); - return get_settings('home') . str_replace($rewritecode, $rewritereplace, get_settings('permalink_structure')); - } else { - return get_settings('home') . '/' . get_settings('blogfilename').$querystring_start.'p'.$querystring_equal.$id; - } + + $cats = get_the_category($idpost->ID); + $category = $cats[0]->category_nicename; + + $rewritereplace = array( + date('Y', $unixtime), + date('m', $unixtime), + date('d', $unixtime), + date('H', $unixtime), + date('i', $unixtime), + date('s', $unixtime), + $idpost->post_name, + $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; } }