From cbe226d621c5d10fd9611d283d050d7552487869 Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 26 Mar 2007 08:08:31 +0000 Subject: [PATCH] Basic theme support for tags. git-svn-id: http://svn.automattic.com/wordpress/trunk@5111 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-content/themes/classic/index.php | 2 +- wp-content/themes/default/index.php | 2 +- wp-includes/category-template.php | 36 +++++++++++++++++++++++++++++ wp-includes/functions.php | 12 ++++++---- 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/wp-content/themes/classic/index.php b/wp-content/themes/classic/index.php index ce020402f..5804f7405 100644 --- a/wp-content/themes/classic/index.php +++ b/wp-content/themes/classic/index.php @@ -8,7 +8,7 @@ get_header();

-
@
+
@
diff --git a/wp-content/themes/default/index.php b/wp-content/themes/default/index.php index ffb0779e9..3c5ad0671 100644 --- a/wp-content/themes/default/index.php +++ b/wp-content/themes/default/index.php @@ -14,7 +14,7 @@
- +
diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php index df102b5cd..74b3b78ca 100644 --- a/wp-includes/category-template.php +++ b/wp-includes/category-template.php @@ -160,6 +160,42 @@ function the_category($separator = '', $parents='') { echo get_the_category_list($separator, $parents); } +function get_post_tags( $post_id = 0 ) { + global $tag_cache, $blog_id; + + $post_id = (int) $post_id; + + if ( !isset( $tag_cache[$blog_id][$post_id] ) ) + update_post_category_cache( $post_id ); // loads $tag_cache + + return $tag_cache[$blog_id][$post_id]; +} + +function get_the_tags( $before, $sep, $after ) { + global $post; + if ( !$post ) + return false; // in-the-loop function + + $tags = get_post_tags( $post->ID ); + if ( empty( $tags ) ) + return false; + + $return = $before; + foreach ( $tags as $tag ) + $tag_links[] = '' . $tag->cat_name . ''; + + $tag_links = join( $sep, $tag_links ); + $tag_links = apply_filters( 'the_tags', $tag_links ); + $return .= $tag_links; + + $return .= $after; + return $return; +} + +function the_tags( $before = 'Tags: ', $sep = ', ', $after = '' ) { + echo get_the_tags( $before, $sep, $after ); +} + function category_description($category = 0) { global $cat; if ( !$category ) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 1b9ad20c2..501d29525 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -635,7 +635,7 @@ function clean_page_cache($id) { } function update_post_category_cache($post_ids) { - global $wpdb, $category_cache, $blog_id; + global $wpdb, $category_cache, $tag_cache, $blog_id; if ( empty($post_ids) ) return; @@ -656,13 +656,17 @@ function update_post_category_cache($post_ids) { return; $post_id_list = join( ',', $post_id_array ); // with already cached stuff removed - $dogs = $wpdb->get_results("SELECT post_id, category_id FROM $wpdb->post2cat WHERE post_id IN ($post_id_list)"); + $dogs = $wpdb->get_results("SELECT post_id, category_id, rel_type FROM $wpdb->post2cat WHERE post_id IN ($post_id_list)"); if ( empty($dogs) ) return; - foreach ($dogs as $catt) - $category_cache[$blog_id][$catt->post_id][$catt->category_id] = &get_category($catt->category_id); + foreach ($dogs as $catt) { + if ( 'category' == $catt->rel_type ) + $category_cache[$blog_id][$catt->post_id][$catt->category_id] = &get_category($catt->category_id); + elseif ( 'tag' == $catt->rel_type ) + $tag_cache[$blog_id][$catt->post_id][$catt->category_id] = &get_category($catt->category_id); + } } function update_post_caches(&$posts) {