Archived topic
WPSP Layout depending on SIdebar
8 replies · Started by Alain Aubry on August 30, 2018
Hi
Fist of all the theme is amazing, in previous posts I did not have an online address to show, now I have one!
I am using WPSP hooked to 'generate_after_main_content' on single posts, as the example below. This is fine.
I passed some $custom_settings to WPSP in order to random search inside the current category.
The most of my posts use sidebar, but some particular post's don't use it.
How can I find if the sidebar is going to be outputted or not, I have tried many things.
add_action( 'generate_after_main_content', 'indigo_related_posts' );
function indigo_related_posts() {
if ( is_singular( 'post' ) ) {
$category = get_the_category();
// if ( is_active_sidebar( 'right-sidebar' ) ) {
$ppp = 3;
$columns = 'col-4';
// } else {
// $ppp = 4;
// $columns = 'col-3';
// }
$custom_settings = array(
'columns' => $columns,
'posts_per_page' => $ppp,
'taxonomy' => 'category',
'tax_term' => $category[0]->slug
);
if ( function_exists( 'wpsp_display' ) ) wpsp_display( 30201, $custom_settings ); // server
}
}
The lines commented out don't work...
A sample of what I want to correct is here: https://www.casa-indigo.com/artigos/cultura/verdade-do-calendario/ this one should be displaying 4 related posts.
Thanks
Hi there,
If I understand correctly the question should be more suitable in one of WP Show Posts forum:
https://wordpress.org/support/plugin/wp-show-posts
https://wpshowposts.com/support/area/pro-support/
If so can you open a topic there?
Thanks!
Posted to: https://wordpress.org/support/topic/wpsp-layout-depending-on-sidebar/ as per your request.
Really is more about GeneratePress than anything else. I need to find out how to detect the presence of the sidebar in one particular post. See the commented out line “if ( is_active_sidebar( ‘right-sidebar’ ) )”.
Ahh ok my mistake :)
I've forwarded this to Tom.
Hi there,
You could try this:
if ( 'right-sidebar' === generate_get_layout() ) {
}
Brilliant!
Thank you so much!
Alain
You're welcome :)
Hi
I am reopening this #664913.
I tried to apply the same solution to a CPT but it did not work.
Do I need to pass the CPT name or something?
A sample of what I want fix is https://www.casa-indigo.com/colaboradores/lucia-borges/
It is correct to display 3 boxes, but using 100% of the space.
Thanks
Hmm, GP uses that same function to add the sidebar layout class to the <body> element, and it's working (right-sidebar).
Can I see your current code?