• What’s the best method (code) to make a list of all the posts that have no tags?

    I want a page of “Untagged posts” on my site. Just showing the titles of each post that are missing tags.

    Is it something to do with query_posts and is_tag == 0 ? I don’t know how to write this code. Please help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • How about a query_posts with no parameters, but in your loop, something like:

    $tag = get_the_tags();
    if (! $tag) {
    echo 'this post has no tags ' . /the_permalink();
    }
    Thread Starter Dgold

    (@dgold)

    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 { ?>
    &plusmn; <small>Tags for</small> &ensp; <a href="<?php the_permalink() ?>" rel="bookmark" title="Entry for <?php the_title(); ?>"><?php the_title(); ?></a> &ensp; <?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) { ?>
    &ne; <small>No tags listed for</small> &ensp; <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.

    Hi,
    Nice archive Dgold. Theres a way to organize by letters? as a directory, or show a next_tag_page_link.

    I have more that 500 tags, and if i display all tags, its not good for my users. It would be nice if have next_tags and previus_tags links, showing 50 tags per page.

    Any solution?

    i have other question, if i have in a post 30 tags i want every page refresh show only 10 tags but random..how i can do?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How can I list all the posts that have no tags yet?’ is closed to new replies.