Add Sidebar to Blog Page only

Hi there,

I would like to only add the the sidebar onto my blog page only. Please advise where it should be added into the child theme.

Kind regards,

Hi There,

Please add the following code under functions.php file locates in your child theme:

function x_get_content_layout() {

	$content_layout = x_get_option( 'x_layout_content' );

	if ( $content_layout != 'full-width' ) {
		if ( is_home() ) {
			$opt    = x_get_option( 'x_blog_layout' );
			$layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
		} elseif ( is_singular( 'post' ) ) {
			$meta   = get_post_meta( get_the_ID(), '_x_post_layout', true );
			$layout = ( $meta == 'on' ) ? 'full-width' : $content_layout;
		} elseif ( x_is_portfolio_item() ) {
			$layout = 'full-width';
		} elseif ( x_is_portfolio() ) {
			$meta   = get_post_meta( get_the_ID(), '_x_portfolio_layout', true );
			$layout = ( $meta == 'sidebar' ) ? $content_layout : $meta;
		} elseif ( is_page_template( 'template-layout-content-sidebar.php' ) ) {
			$layout = 'content-sidebar';
		} elseif ( is_page_template( 'template-layout-sidebar-content.php' ) ) {
			$layout = 'sidebar-content';
		} elseif ( is_page_template( 'template-layout-full-width.php' ) ) {
			$layout = 'full-width';
		} elseif ( is_archive() ) {
			if ( x_is_shop() || x_is_product_category() || x_is_product_tag() ) {
				$opt    = x_get_option( 'x_woocommerce_shop_layout_content' );
				$layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
			} else {
				$opt    = x_get_option( 'x_archive_layout' );
				$layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
			}
		} elseif ( x_is_product() ) {
			$layout = 'content-sidebar';
		} elseif ( x_is_bbpress() ) {
			$opt    = x_get_option( 'x_bbpress_layout_content' );
			$layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
		} elseif ( x_is_buddypress() ) {
			$opt    = x_get_option( 'x_buddypress_layout_content' );
			$layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
		} elseif ( is_404() ) {
			$layout = 'full-width';
		} else {
			$layout = $content_layout;
		}
	} else {
		$layout = $content_layout;
	}

	if ( is_home() ) {
		$layout = 'content-sidebar';
	}

	return $layout;
}

After that create a new sidebar for blog page only under Appearance > Sidebars:

Hope it helps :slight_smile:

Hi Thai,

I’m sorry as I am a newbie at this. But I was just looking into a similar issue and wanted to insert a sidebar just into my blog page (and blog posts pages). I have 4 pages right now - home, services, let’s chat, blog - and when I go to “Layout & Design” and select “Content Left, Sidebar Right” - it adds a sidebar to my Services page, but not my Blog page. Do you know how I can fix this? Plus I have no idea how or why it’s not inserting a sidebar into my let’s chat page. (my website is www.kendallu.com)

I am not sure where to find where I can input the functions.php code into the child theme. I have very little developer knowledge so I don’t even know where to find that haha. So if I don’t need to do that, awesome. But if I do need to input code into the functions.php - would you be able to show me where I could do that and how?

Thank you so much for your help!

Kendall

Hi Kendall,

Please also try checking the Layout setting in X > Theme Options > Blog and set it to Use Global Content Layout then check in Layout and Design setting and set the Content Layout to Content Left, Sidebar Right.

Hope this helps.

Hi Jade,

Thank you! Both of my settings are set as you suggested. So looks like I’m good there. I’m just unsure as to how I can get the sidebar to appear in my Blog page, not in my Services page.

Appreciate the help though!

-Kendall

You know what, I got it to show up on my Blog finally. I had made the Blog Sidebar but hadn’t added any widgets to it. But now, I just would like my Services page to not have the sidebar because it throws off the formatting I had with it.

Any tips for that? Again, the site is www.kendallu.com

Thanks!

Hi Kendall,

Please edit the Services page then set the page template to Fullwidth.

Hope this helps.

I saw that suggested in another forum but when I go to Pages, under Page Attributes, it does not give me the “Template” option. Only “Parent” and “Order” appear and I have no idea why. Would that have been disabled somehow?

I so appreciate your help!!

Forgive me! I did find it. I was looking on my Blog page and that didn’t give me the template option - probably for good reason. So I got it fixed! So sorry for the runaround. Thank you so much for your help!! :slight_smile:

Best,
Kendall

Hey Kendall,

You’re welcome!
We’re glad we were able to help you out.

Regards.

Great thanks for that - how do I get my banner image to be placed in a full width div and full the white space in the top right corner. https://www.jups.co.za/blog/

Hey @Ashbeggs,

Add this code in X > Theme Options > JS.

jQuery('.blog .cs-content').insertAfter('.x-masthead');

Hope that helps.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.