Echo the current queried tag only
-
Hello,
I’ve searched the forums and Googled, but haven’t had any luck finding a solution to my how-to question. It could be that I’m going about it all wrong, so I’m open to ‘best practice’ solutions too.
Apologies for the long post, I just wanted to explain it as thoroughly as possible. The site is in development locally, so unfortunately I’m unable to provide a link.
I have a page template which uses multiple queries to display one post per a selection of tags.
For example:
$thistag = new WP_Query('tag=this-tag&showposts=1'); if ($thistag->have_posts()): while ($thistag->have_posts() ) : $thistag->the_post(); get_template_part( 'specialtags-loop' ); endwhile; endif; wp_reset_query(); $thattag = new WP_Query('tag=that-tag&showposts=1'); if ($thattag->have_posts()): while ($thattag->have_posts() ) : $thattag->the_post(); get_template_part( 'specialtags-loop' ); endwhile; endif; wp_reset_query(); $anothertag = new WP_Query('tag=another-tag&showposts=1'); if ($anothertag->have_posts()): while ($anothertag->have_posts() ) : $anothertag->the_post(); get_template_part( 'specialtags-loop' ); endwhile; endif; wp_reset_query();
My loop is just a standard WordPress loop, and correctly displays a list of posts comprising one of each of the requested tags:
Post Title
Post ExcerptPost Title
ExcerptPost Title
ExcerptWhat I want to do (if it’s possible) is display the ‘nice name’ of each queried tag, without having to resort to hard-coding each tag name individually – just to differentiate between the posts. Most of my posts have multiple tags, which is why I’m trying to get it to display the queried tag only.
What I’d like is for the page to show something like:
This Tag
Post Title
Excerpt
Read more from This TagThat Tag
Post Title
Excerpt
Read more from That TagAnother Tag
Post Title
Excerpt
Read more from Another TagHopefully this makes some sense, and hopefully you can help. Much appreciated.
- The topic ‘Echo the current queried tag only’ is closed to new replies.