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
This commit is contained in:
westi 2009-10-08 17:27:51 +00:00
parent 88dfeaca8a
commit 7d2a85c40e
1 changed files with 16 additions and 4 deletions

View File

@ -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);
}