I haven’t coded for a few years and it’s taking longer than anticipated to get back on the ball.
Here’s my function:
function tags(){
if (is_page('tag')){$tags = get_tags();}
else{$tags = get_the_tags();}
if (!$tags){echo "";}
else{
$html = '<ul class="tags">' . "\r\n\t" . '<li>Tags: </li>' . "\r\n\t" . '';
foreach ($tags as $tag){
$tag_link = get_tag_link($tag->term_id);
global $post;
//get tag_group_ids
$tag_group_ids = get_option('tag_group_ids', array());
$i = array_search($tag->term_group, $tag_group_ids);
//get tag_group_labels and change to lowercase
$tag_group_labels = get_option('tag_group_labels', array());
$lower = array_map('strtolower', $tag_group_labels);
//get tag description and change ascii
$description = str_replace('"', "''", $tag->description);
$tagdescription = str_replace("=", "\n", $description);
//get post excerpt relating to tag slug - CURRENTLY TESTING
$tagslug = $tag->slug;
$args = array('name' => $tagslug);
$excerpt = get_posts($args);
$output = $excerpt[0]->post_excerpt;
echo '<pre>';
var_dump ($excerpt);
echo '</pre>';
$outputreplace = str_replace('"', "''", $output);
$postexcerpt = str_replace("=", "\n", $outputreplace);
//change speechmarks for $tag->name
$tagname = str_replace('"', "''", $tag->name);
//CURRENTLY TESTING
$the_slug = 'uk';
$the_slug = $tag->slug;
$argz = array('name' => $the_slug);
$my_posts = get_posts($argz);
$html .= '<b>ID: </b>' . $my_posts[0]->ID . "\n\n";
$html .= '<b>Name: </b>' . $my_posts[0]->post_name . "\n\n";
$html .= '<b>Excerpt: </b>' . $my_posts[0]->post_excerpt . "\n\n";
$html .= '<b>Slug: </b>' . $tag->slug ."\n\r\n\r";
echo '<pre>';
print_r($tag->slug);
echo '</pre>';
//output
$html .= '<li class="' . $lower[$i] . ' ' . $tag->slug . ' tag">' . "\n\t";
$html .= '<a href="' . $tag_link . '"';
$html .= ' title="' . $tagname . "\n\n";
if (!empty($postexcerpt)){
$html .= $postexcerpt . "\n\n";
}
elseif (!empty($tagdescription)){
$html .= $tagdescription . "\n\n";
}
else{
$html .= "No tag description or post excerpt yet." . "\n\n";
}
$html .= 'Tagged in ' . $tag->count . ' posts' . "\n\n";
$html .= 'Catergory: ' . $tag_group_labels[$i] . "\n" . '">';
$html .= $tag->name;
$html .= ' <sup>[' . $tag->count . ']';
if (!empty($outputreplace)||($description)){
$html .= '[D]';
}
$html .= '</sup></a></li> '. "\n\n\t";
}
$html .= '</ul>';
echo $html;
echo "\r\n";
}
}