From cbe226d621c5d10fd9611d283d050d7552487869 Mon Sep 17 00:00:00 2001
From: matt <matt@1a063a9b-81f0-0310-95a4-ce76da25c4cd>
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 ce020402f3..5804f74058 100644
--- a/wp-content/themes/classic/index.php
+++ b/wp-content/themes/classic/index.php
@@ -8,7 +8,7 @@ get_header();
 
 <div class="post" id="post-<?php the_ID(); ?>">
 	 <h3 class="storytitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
-	<div class="meta"><?php _e("Filed under:"); ?> <?php the_category(',') ?> &#8212; <?php the_author() ?> @ <?php the_time() ?> <?php edit_post_link(__('Edit This')); ?></div>
+	<div class="meta"><?php _e("Filed under:"); ?> <?php the_category(',') ?> &#8212; <?php the_tags('Tags: ', ', ', ' &#8212; '); ?> <?php the_author() ?> @ <?php the_time() ?> <?php edit_post_link(__('Edit This')); ?></div>
 
 	<div class="storycontent">
 		<?php the_content(__('(more...)')); ?>
diff --git a/wp-content/themes/default/index.php b/wp-content/themes/default/index.php
index ffb0779e94..3c5ad06715 100644
--- a/wp-content/themes/default/index.php
+++ b/wp-content/themes/default/index.php
@@ -14,7 +14,7 @@
 					<?php the_content('Read the rest of this entry &raquo;'); ?>
 				</div>
 
-				<p class="postmetadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?></p>
+				<p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?></p>
 			</div>
 
 		<?php endwhile; ?>
diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php
index df102b5cdf..74b3b78cac 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[] = '<a href="' . get_category_link($tag->cat_ID) . '">' . $tag->cat_name . '</a>';
+
+	$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 1b9ad20c24..501d29525c 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) {