Thanks MichaelH! Once again you write history. (Well, it’s like magic, you know, I pop the code in my custom page template for Tags Archive, and a page of data generates, a fresh look at all those tags I’ve been making for years suddenly appears). Very useful. I’m going to share what I made: a complete Tags Archive for one of my sites.
I did use some parameters on query_posts
. I used orderby=title&order=asc
to make my posts list alphabetical, and I used &showposts=-1
to make the lists include ALL posts in my website, which is what I want for a comprehensive tags archive of this particular site. (It is alphabetical because it is not a blog, it’s more like a collection of reviews where the post title is like, for example, a song – book – or movie title).
So first I’ve got my regular post/page loop, that’s got the introduction “This is my tags archive”. Next I pull in some cool codes for showing 50 random tags in a cloud, then the 50 most common tags in weighted order, then a comprehensive list of all my tags (with a special code to show the total # of tags, right now I have 885).
<h3>Random remix of tags: <small>Tag Cloud, Tag Poetry, Tag Soup</small></h3>
<?php wp_tag_cloud('number=50&format=list&order=RAND'); ?>
<h3>Most common tags:</h3>
<?php wp_tag_cloud('number=50&format=list&orderby=count'); ?>
<h3>All <?php if (function_exists('tagstats')) { tagstats(); } ?> tags in alphabetical order:</h3>
<?php wp_tag_cloud('smallest=10&largest=10&number=0&format=list'); ?>
After that I have the 2 query_posts loops, back to back. I went with 2 query_posts
after the main loop. That’s ok right?
First one shows all my posts that have tags. It shows each post title, and which tags that post has.
<?php query_posts('orderby=title&order=asc&showposts=-1'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php
$tag = get_the_tags();
if (! $tag) { ?>
<?php } else { ?>
± <small>Tags for</small>   <a href="<?php the_permalink() ?>" rel="bookmark" title="Entry for <?php the_title(); ?>"><?php the_title(); ?></a>   <?php the_tags(' ', ' | ', ''); ?>
<?php } ?>
<?php endwhile; ?>
<?php endif; ?>
Second I’ve got the “No tags” list of untagged posts. This will help me see which posts to go back and tag. I’m also planning to use the TagThis plugin to allow my users to help me tag those posts missing tags.
<h3>No tags yet: <small>These posts are untagged so far. Readers may suggest tags.</small></h3>
<ul><li>Can you think of any good label, category, or keyword for the article?</li>
<li>Feel free to post a Comment about what tags you think would work well here.</li></ul>
<?php query_posts('orderby=title&order=asc&showposts=-1'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php
$tag = get_the_tags();
if (! $tag) { ?>
≠ <small>No tags listed for</small>   <a href="<?php the_permalink() ?>" rel="bookmark" title="Entry for <?php the_title(); ?>"><?php the_title(); ?></a>
<?php } else { ?>
<?php } ?>
<?php endwhile; ?>
<?php endif; ?>
That’s my Tags archive, so far. The template is called something custom like archive-my-tags.php, and I selected it in the Edit Page menu for my page with the title of “Tags On My Site” and the slug of “tag”.
I also made a tag.php that shows all the posts associated with any particular tag. On the top of that tag.php template, I placed an obvious link back to the comprehensive Tags Archive at mysite.com/tag/
It all makes sense and lets you surf around through tags nicely.
Thanks again for the help on the Support forum. If anyone has ideas or sees corrections to the above code, please post. I’m learning.