Support » Fixing WordPress » Display Only TAGGED Post on Category page

  • I want to display just one post in the Category Page, and that post will be chosen if it has a specific TAG and belongs to that category.

    So lets say I create a post and add a TAG called “Main Cat Post”.
    I might actually have 5 posts with a TAG called Main Cat Post, however
    they will all be in different categories.

    I think im supposed to be looking in the archive.php file…(I dont have a category.php) I see the loop but thats it.

    <?php while ( have_posts() ) : the_post() ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • I ALMOST got it..I have TAGS working, unfortunately it shows the post, even if the post doesnt belong in the category page that i’m on.

    <?php $category = get_the_category(); ?>
    <?php query_posts('cat=$category&tag=test');?>
    <?php while ( have_posts() ) : the_post() ?>

    Why is this?

    Finally got it..Has to do with an old WP bug where the category name cannot be resolved outside main loop with query-posts.

    <?php foreach(get_the_category() as $category) { $cat=$category->cat_ID; }
    query_posts("cat=$cat&tag=test"); ?>

    It has to be done this way..not sure why..they need to fix this by now.
    Even if I had replaced cat=catid in 2nd post, instead of cat=categoryname it wouldnt work.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display Only TAGGED Post on Category page’ is closed to new replies.