Support » Fixing WordPress » Tag archive showing all posts

  • I have tag archives which are (obviously) supposed to show only the posts with a certain tag. However, mine display the same posts whatever tag is meant to be showing.

    For example:

    http://www.davidfordfans.com/tag/state-of-the-union/
    http://www.davidfordfans.com/tag/cheer-up/
    http://www.davidfordfans.com/tag/songs-for-the-road/

    show the same, as do all the other tag pages.
    I have Simple Tags installed, if that’s any relevance.

    What am I doing wrong? Here’s the code for it:

    <?php single_tag_title('Currently browsing: '); ?></h1>
    <?php query_posts('cat=6'); ?>
    
    			<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    			<div class="primary">
    				<h2><?php
    foreach((get_the_category()) as $cat) {
    echo $cat->cat_name . ' ';
    } ?>: <a>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    			</div>
    			<hr class="hide" />
    			<div class="secondary">
    				<div class="featured">
    					<dl>
    						<dt>Comments:</dt>
    						<dd><?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></dd>
    					</dl>
    				</div>
    			</div>
    			<div class="clear"></div>
    			<div class="divider"></div>
    			<?php endwhile; ?>
    
    			<?php else : ?>
    
    			<?php endif; ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Aren’t you only going to see posts in category 6 with this
    <?php query_posts('cat=6'); ?>

    Thread Starter wibbler

    (@wibbler)

    Hi,

    Well, yes – but what I’m trying to acheive with that loop is showing all in Category 6 with that whatever tag is meant to be displayed. Eg. http://www.davidfordfans.com/tag/cheer-up/ should display all in Category 6 with the tag of “cheer up”…!

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Your problem is that the <?php query_posts('cat=6'); ?> overrides the specified tag and everything else. It’s just going to give you all posts from category 6.

    Try this instead:
    <?php query_posts($query_string . '&cat=6'); ?>

    That will keep the specified tag in the query and just add the category parameter.

    Note, this might not work, I’ve never tried to do both categories and tags in the same query.

    Thread Starter wibbler

    (@wibbler)

    Thanks Otto42 – although you’re right, that didn’t work!

    Maybe, instead, there’s a way to order results by category instead, all in one loop?
    So, the end result could be:
    Tag: Tag 1
    Category 1:
    Post 4
    Post 7
    Post 9
    Category 2:
    Post 3
    Post 8
    Category 3:
    Post 1
    Post 2
    Post 5

    Can that be done, with the Category headers in place?!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Tag archive showing all posts’ is closed to new replies.