certainlyakey
6/23/2014 - 1:33 PM

Display multiple tag names on Tag Archives pages

Display multiple tag names on Tag Archives pages

<?php
/*single_cat_title displays only one tag name, this function 
makes it possible to display more than one. Links to tags support only 2 tags!
URL is:
tagname1 AND tagname2: /tag/tagname1+tagname2/[page/3]
tagname1 OR tagname2: /tag/tagname1,tagname2/[page/3] //doesn't work with this function yet
*/
function get_multiple_tags_names_in_tag_archives() {
    $tag_permalink_base = 'tag';
    $page_permalink_base = 'page';
    $findpage = '/\/'.$page_permalink_base.'\/\d+/';
    $nice_tag_query = $_SERVER['REQUEST_URI'];
    $nice_tag_query = str_replace($tag_permalink_base,'', $nice_tag_query);
    $nice_tag_query = preg_replace($findpage,'', $nice_tag_query);
    $nice_tag_query = str_replace('/','', $nice_tag_query);
    $nice_tag_query_array = explode('+',$nice_tag_query);
    $sep = '</a></span>, <span><a href="/'.$tag_permalink_base.'/'.$nice_tag_query_array[1].'">';
    $nice_tag_query = str_replace('+', $sep, $nice_tag_query);
    return '<span><a href="/'.$tag_permalink_base.'/'.$nice_tag_query_array[0].'">'.$nice_tag_query.'</a></span>';
}

//This optional function returns different suffixes (supplied as arguments) based on single or multiple tags are presented in archive page (uses output of get_multiple_tags_names_in_tag_archives() function)
function changeSuffixesBasedOnSingleOrMultipleTag($singleSuffix,$multipleSuffix) {
$string = get_multiple_tags_names_in_tag_archives();
$hasMultipleTags = strpos($string, ",");
if ($hasMultipleTags === false) {
    return $singleSuffix;
}
else {return $multipleSuffix;}
}
?>