jumust
Member
Posted 10 months ago #
Hi,
I want to build a featured section for each category page that will show one post of the current category page by a specific tag (featured).
I ended up using this but it shows the same post with the "featured" tag in all categories....
How can I use the variable category to get the featured post from the current category?
untested - try to add the current category into the query:
$args = array(
'category__in' => array(get_query_var('cat')),
'posts_per_page' => 1,
'tag' => 'featured',
);
http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
jumust
Member
Posted 10 months ago #
Great it worked! Thanks
what should I add to not duplicate the featured post with posts the loop below the featured section?
what should I add to not duplicate the featured post with posts the loop below the featured section?
check:
http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action
particular the section after the headline 'Note for Multiple Posts in the First Category'
i.e. using an array for $do_not_duplicate and the 'post__not_in' parameter in a query for the rest of the posts.
example - assuming that you have the post ID of the 'featured' post in the $do_not_duplicate array;
global $wp_query;
$args = array_merge( $wp_query->query, array( 'post__not_in' => $do_not_duplicate ) );
query_posts( $args );
http://codex.wordpress.org/Function_Reference/query_posts#Preserving_Existing_Query_Parameters
you could also paste the full code of your category archive template (into a pastebin ...) and someone might have a look at your code.
jumust
Member
Posted 10 months ago #
Awesome I figured that out
Thanks