Forums

Tag archive showing all posts (5 posts)

  1. wibbler
    Member
    Posted 4 years ago #

    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; ?>
  2. MichaelH
    Volunteer
    Posted 4 years ago #

    Aren't you only going to see posts in category 6 with this
    <?php query_posts('cat=6'); ?>

  3. wibbler
    Member
    Posted 4 years ago #

    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"...!

  4. Otto
    Tech Ninja
    Posted 4 years ago #

    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.

  5. wibbler
    Member
    Posted 4 years ago #

    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?!

Topic Closed

This topic has been closed to new replies.

About this Topic