From 44fc49bb90f800703087f3062f90211307a5beb3 Mon Sep 17 00:00:00 2001 From: Peter Westwood 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: https://develop.svn.wordpress.org/trunk@12010 602fd350-edb4-49c9-b593-d223f7449a82 --- 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); }