Hi,
i want to add on the top of the sidebar a picture with link or a specific post thumbnail depending on the post category. For each category to have a different thumbnail/image.
On my old theme i added this code in the sidebar.php file:
<?php if ( in_category( ‘xxxxxx’ ) ) {?>
<div id=”label”></div>
<?php }?>
Where can i add this code in order to show the div label or what can i add in the widget sidebar for this?
Creating a separate sidebar for each category is an option but i have about 20 cat and i have to create 20 separate sidebars for this and i prefer to keep this as backup solution.
Thank you
Hi,
It will still work in sidebar.php but the one from the wp-booster folder in our case: http://screencast.com/t/HpXCl3pXzb
It will not work in sidebars created in visual composer though(2/3 + 1/3 column layout) but on pages you can add it with a single image element.
Thank you!
Hi,
not sure i understand where i have to add the php code in sidebar.php file, i’m using only the default sidebar.
The solution 2 with the widgets, on sidebar in a new widget i added the following code for one post
[vc_row][vc_column][vc_posts_slider count="1" interval="3" thumb_size="large" posts_in="3429"][/vc_column][/vc_row]
but i want to make it somehow change depending on the category.
On the home page i want to hide this.
-
This reply was modified 10 years by
dragos_2p.
Hi,
You can use the in_category function and use the do_shortcode function as well if you plan to use visual composer shortcodes.
You wanted it to show at the top of every sidebar so you would place the code at the top of the sidebar file. like so:
http://screencast.com/t/AsflY1dxoby8
if (in_category('category-slug')){
echo do_shortcode('[vc_posts_slider count="1" interval="3" thumb_size="large" posts_in="3429"]');
}
elseif (in_category('category-slug2')){
echo do_shortcode('[vc_posts_slider count="1" interval="3" thumb_size="large" posts_in="3429"]');
}
Hope this helps.