Site logo

Archived topic

WPSP Layout depending on SIdebar

8 replies · Started by Alain Aubry on August 30, 2018

Viewing posts 1–9 of 9

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

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?

This archived topic is closed to new replies.