WordPress.org

Ready to get started?Download WordPress

Forums

Display Only TAGGED Post on Category page (3 posts)

  1. denutza
    Member
    Posted 1 year ago #

    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() ?>
  2. denutza
    Member
    Posted 1 year ago #

    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?

  3. denutza
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.