single_tag_title() and multiple_tag_title()
-
I was looking or a mulitple_tag_title() to do the same job as single_tag_title, but there isn’t a good solution out there.
I found a couple of forum postings, but they didn’t quite address my need. This isn’t a big enough piece of code to warrant a plugin, so just stick this in your themes functions.php
/*
==================================================================
gs_get_tag
A function to take a tag name as an argument and return
the tag object.
================================================================== */
if ( !function_exists('gs_get_tag') )
{
global $GS_ALL_TAGS;
$GS_ALL_TAGS = get_tags();
function gs_get_tag($name)
{
global $GS_ALL_TAGS;
if (is_array($GS_ALL_TAGS) && count($GS_ALL_TAGS) > 0 )
{
foreach ($GS_ALL_TAGS as $tag)
{
if ($tag->name === $name) { return $tag; }if ($tag->slug === $name) { return $tag; }
if ($tag->slug === strtolower($name)) { return $tag; }
}
}
}
}/*
==================================================================
A custom function to display multiple tag titles.
gs_multiple_tag_title
================================================================== */
if (!function_exists('gs_multiple_tag_title'))
{
function gs_multiple_tag_title()
{
// assume global wp_query.
global $wp_query;
$tags = $wp_query->query_vars['tag'];$tags_array = split (',',$tags);
if (!is_array ($tags_array) || count ($tags_array) < 1 ) { return; }foreach ($tags_array as $tags_block)
{
foreach( split(' ',$tags_block) as $tag )
{
$tag_obj = gs_get_tag($tag);
$multiple_tags .= $tag_obj->name.' ';
}
$multiple_tags = rtrim($multiple_tags,' ').', ';}
$multiple_tags = rtrim($multiple_tags,', ');return $multiple_tags;
}
}Then to use this in your theme just do this.
<h1><?php echo gs_multiple_tag_title(); ?></h1>
- The topic ‘single_tag_title() and multiple_tag_title()’ is closed to new replies.