I am trying to get a specific sidebar show when post is in specific categories but the code that I have doesn’t seems to work.
Here is the code:
<div class="sidebar">
<?php if (is_single() && in_category('2') ) { ?>
<?php dynamic_sidebar( 'blog-sidebar' ); ?>
<?php } else { ?>
<?php dynamic_sidebar( 'general-sidebar' ); ?>
<?php }
<!-- Load posts related to current post -->
$currentcat = get_query_var('cat');
$relatedargs = array (
'cat' => 'array($currentcat)',
'posts_per_page' => '2',
'ignore_sticky_posts' => true,
'orderby' => 'rand',
'post__not_in' => array( $post->ID ),
'cat' => '-1'
);
$relatedposts = new WP_Query( $relatedargs ); ?>
<?php if ( $relatedposts->have_posts() ) : ?>
<?php while ($relatedposts -> have_posts()) : $relatedposts -> the_post(); ?>
<div <?php post_class('col-4')?>>
<h3><a class="h3" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php
global $more; // Declare global $more (before the loop).
$more = 0; // Set (inside the loop) to display content above the more tag.
the_content("Lees verder ");
?>
</div>
<?php endwhile; wp_reset_postdata();?>
<?php endif; ?>
</div><!--/.sidebar -->
But even when I am on post that has cat 2 it still shows the else sidebar. What am I doing wrong?