denutza
Member
Posted 11 months 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() ?>
denutza
Member
Posted 11 months 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?
denutza
Member
Posted 11 months 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.