From 7d2a85c40e4a430d191a25ccbf9e8a9d1f7a62eb Mon Sep 17 00:00:00 2001 From: westi Date: Thu, 8 Oct 2009 17:27:51 +0000 Subject: [PATCH] Allow for tag templates to be linked by tag id as well as name. Fixes #10868. git-svn-id: http://svn.automattic.com/wordpress/trunk@12010 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/theme.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/wp-includes/theme.php b/wp-includes/theme.php index bebeb0afa7..7d22ca55d2 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -618,16 +618,28 @@ function get_category_template() { /** * Retrieve path of tag template in current or parent template. * - * Works by retrieving the current tag name, for example 'tag-wordpress.php' and will - * fallback to tag.php template, if the name tag file doesn't exist. - * + * Works by first retrieving the current tag name, for example 'tag-wordpress.php' and then + * trying tag ID, for example 'tag-1.php' and will finally fallback to tag.php + * template, if those files don't exist. + * * @since 2.3.0 * @uses apply_filters() Calls 'tag_template' on file path of tag template. * * @return string */ function get_tag_template() { - $template = locate_template(array("tag-" . get_query_var('tag') . '.php', 'tag.php')); + $tag_id = absint( get_query_var('tag_id') ); + $tag_name = get_query_var('tag'); + + $templates = array(); + + if ( $tag_name ) + $templates[] = "tag-$tag_name.php"; + if ( $tag_id ) + $templates[] = "tag-$tag_id.php"; + $templates[] = "tag.php"; + + $template = locate_template($templates); return apply_filters('tag_template', $template); }