whitehats
Member
Posted 1 year ago #
Hi,
I want to display content from the sticky post of the category of the current post. I have been able to display the sticky posts of current category on the category template, in the sidebar. However, if I have a category Mustang in the category Cars, I want to display only sticky posts from Cars in the sidebar when one is viewing Mustang post.
How is this achievable?
Thanks,
-tejas
whitehats
Member
Posted 1 year ago #
I must be getting really smart now1! :)
Here is the code
<?php if (is_category() || is_single()) {
$cat = get_the_category($post->ID);
echo '<h3 class="textcenter">'.$cat[0]->cat_name.'</h3>';
$args = array(
'post__in' => get_option('sticky_posts'),
'cat' => $cat[0]->cat_ID
);
query_posts($args);
if ( have_posts() ) : while ( have_posts() ) : the_post(); {
the_content();
}
endwhile;
endif;
}
?>
Hope it helps you as it helped me!