Add Sidebar To Post Page

hi

I have been trying to add create a new template which will be the new look of my posts pages. I have Sidebar Left, Content Right set in Layout & Design and under Blog, it is set to Global Content Layout. I have created a sidebar and added an Essential Grid to it.

The issue is when I go to the page, the new sidebar does not show up; no sidebar shows at all. Do I need to edit the default post page template settings to include sidebar all the time? If so, how is this done?

The post is currently called Blog Template. Incidentally, is this the best way to setup a template for my posts pages? To create a post with everything in it I want and then save it as a template?

cheers

Hey @guybower1,

I’d first like to answer the question about “setup a template for my posts pages?”. For now, the only way is to override the single post PHP template. That needs custom development though so that is beyond the scope of our theme support. We can maybe point you in the right direction if you’re comfortable with doing customizations on your own.

In the future, we will be adding a Layout Builder which will allow you to create single and archive pages. You won’t have to work with PHP any more.

Your site is protected by htaccess and I couldn’t log in using the credentials you’ve posted. Please give us access to that as well as give us the URL of the page which is not showing a sidebar.

image

Thanks.

hi Christian

My bad…I just noticed a typo in the user. The password is correct; sincere apologies. I have corrected it now

Regards

Hello @guybower1,

Thanks for updating. The issue is coming from your custom PHP code. You have added this:

// Remove sidebar content from all bar blog index
// =============================================================================
if ( ! function_exists( 'x_get_content_layout' ) ) :
  function x_get_content_layout() {
    $content_layout = x_get_option( 'x_layout_content' );
    if ( $content_layout != 'full-width' ) {
      if ( is_home() ) {
        $layout = 'content-sidebar';
      } elseif ( is_singular( 'post' ) ) {
        $layout = 'full-width';
      } 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 = 'full-width';
      } 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_page( 13314 )) {
        $layout = 'full-width';
    }
    return $layout;
  }
endif;

Because of this lines:

} elseif ( is_singular( 'post' ) ) {
        $layout = 'full-width';
      }

The layout value must be set to content-sidebar or sidebar-content if you want to display a sidebar in your single blog posts.

Hope this helps.

Hi Ruenel

Is that the functions.php file? Sorry, just the file name is cut off in your post

Regards

No worries there Ruenel. Changed that and now have the sidebar appearing on the left. I will play with width % to get what I want, but there is an odd behaviour with the post page background image. When I have added one to the homepage, it sat above the navbar, but the image on this post page sits partially above the navbar, mainly below the navbar and spills over into the sidebar.

Is it at all possible to have the background image of the page behave like all other page background images and sit just be above the navbar and not below and certainly not into the sidebar?

My question earlier was just a general one about creating a new look for my posts page and I wonder if I am going about it the right way. What I am doing is creating a new post, and brining in all the elements I want. Once the look of the page is right, save it as a template to use for all subsequent posts. Is this the best way to do this?

Thanks in advance. Hopefully you know of a way to rectify the post page background image. The post is called Blog template

Regards

Hey @guybower1,

Regarding the post background image, the difference between your post and your home page is your home page has Slider Above Masthead. That’s not available for posts. The content of the page also does not cover the screen, unlike the home page which uses a Blank No Container page template.

For your question:

Out of the box, no. It’s only possible with custom development. Basically, you or a developer need to add space above the header like the home page for single posts only and also cover the content area with a white background so you won’t see the spillover.

I’d strongly recommend you wait for the Layout Builder feature so that you won’t have to custom develop the layout that you need.

If you will not change the style of your post in the future then this could be feasible for you. It’s important to remember that the method you mentioned is not global. If you’re going to change styles often or need to update the post style, later on, you need to change each and every post.

Your options would be to wait for the Layout Builder or have a developer customize the single post template as I’ve said previously.

Thank you for understanding.

hi Christian

Thanks so much for your reply.

You indicated that Slider Above Masthead is not available for posts. Surely there is a workaround, like editing the relevant php file for the child theme.

Can you possibly indicate which php file controls that particular element, as there are number of them with the term header in them? Are you also able to indicate what the edit would be?

What I am simply trying to do is to have all posts pages with a full width image above the masthead; an image which does not spill below the masthead nor into the sidebar

In the meantime, any idea on when the Layout Builder will be rolled out?

Thanks so much for your time

Hey @guybower1,

There is no filter/hook available to enable the slider options for posts. However, it is possible to add a slider on top of the single posts by making use of the x_before_masthead_begin hook then you can use the slider shortcode to in the hook function.

It would be pretty much the same as the code suggested here:

You just need to replace x_after_view_global__navbar to the x_before_masthead_begin hook.

You can find all of the list of actions, hooks, and filters here:

We currently do not have any ETA when the Layout Builder will be rolled out at the moment.

Hope this helps you get started.

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