Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1167316

    gibzs
    Participant

    Hello X

    I have gone through several search results pages trying to find a solution for adding a sidebar to individual blog posts but i can’t seem to find a working solution for my case.

    Since i only want the sidebar on the individual blog posts, I cannot use the global settings in the customizer because that will make changes to all posts and pages. I hence tried adding a sidebar via Appearance>Sidebars which seems also not to work after selecting blog display options.

    I have also tried to manage my sidebars and created a new sidebar called “Blog Sidebar” and removed any widgets from the main sidebar and only left widgets in the new sidebar “Blog Sidebar” This works partially because it now creates an unwanted space for the empty widget area for other pages and shows for the “Blog Sidebar” This is also inadequate because it only works for the blog posts page(which is a custom link) but not the individual blog posts.

    I have also activated the Masonry style which is a very good feature but does not entirely help because it also does not apply to the individual blog posts.
    I also can’t fix this issue using template options in page attributes because my blogs are not pages but posts which appear not to have this option.

    Could i be skipping something or is there another way to do this? Sorry for the long post, i just wanted to ensure that i gave all my particulars.

    My PHP version, WordPress version, X theme version, Cornerstone and all plugins are up to date.
    Website link: http://www.citymall.co.ke

    I will appreciate any assistance.

    David

    #1167317

    gibzs
    Participant
    This reply has been marked as private.
    #1167620

    Paul R
    Moderator

    Hi,

    Yes, you are correct it’s not an option.

    To achieve that, add the code below in your child theme’s functions.php

    
    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 = '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_singular( 'post' ) ) {
            $layout = 'content-sidebar';
        }
        
        return $layout;
    
      }
    

    You may add it after this line

    // Additional Functions
    // =============================================================================

    Hope that helps.

    #1167728

    gibzs
    Participant

    Hello

    Im looking at the functions.php file and i have no idea where or how to place that code. I know that if i mess up anything to do with my theme’s stylesheet i’m done and i definitely have no idea how to remedy it.

    Kindly assist

    #1167795

    Paul R
    Moderator

    Hi David,

    Kindly install and activate a child theme first.

    How to Setup Child Themes

    Then Navigate to Appearance > Edit

    Please see screenshot – http://screencast.com/t/VLhpOec3

    #1168011

    gibzs
    Participant

    Hello

    I already have a child theme installed and the website is currently on the child theme.

    #1168366

    Joao
    Moderator

    Hi Therem,

    You need to access your website FTP or Cpanel and go to Wp-Content/Themets/X Child/

    Inside you will find the file, download it, use notpad to add the changes, and upload and replace.

    Hope it helps

    Joao

    #1169519

    gibzs
    Participant

    Hello

    First i’d like to apologise because i had misunderstood Paul’s reply,but i finally got it and the FTP method from Joao worked fine.

    The sidebar appears on individual blog posts but just as a space. However i found out that i can activate the widgets to appear by ticking on each post which seems to work fine.

    The sidebar widget doesn’t appear on the main blog page but i turned on the Masonry feature which makes it look fine and i am content with the results.

    However, it would be really convenient if the widgets appeared on the sidebar automatically for each blog post created instead of having to select each blog post manually in “Manage Sidebars”.

    Thank you so much X for the wonderful support.

    David

    #1169856

    Rue Nel
    Moderator

    Hello David,

    You can override the sidebar settings and set the name of your desired sidebar to appear on single posts. Since you already have your child theme active and ready, please insert this following code in your child theme’s functions.php file.

    function assign_custom_sidebar($sidebar){
      if ( is_single() ){
        return 'ups-sidebar-sample';
      }
      return $sidebar;
    }
    add_filter( 'ups_sidebar', 'assign_custom_sidebar');

    Please do not forget to replace the sidebar ID ‘ups-sidebar-sample’ with your own sidebar ID.

    Hope this helps.

    #1170051

    gibzs
    Participant

    Hello X

    I have added the code suggested by Rue Nel and it partially works as it creates the sidebar space automatically on each new blog post created. Is there a way it can also automatically show the widgets in the sidebar without manually selecting each blog post?

    David

    #1170071

    Christian
    Moderator

    Hey David,

    Regretfully this isn’t a feature offered by X. It could be possible with custom development, but this would be outside the scope of support we can offer. You might want to contact our trusted partners who caters X setup and customization needs. Please see https://community.theme.co/custom-development/.

    Thanks for understanding. Take care!

    #1170086

    gibzs
    Participant

    Hello X

    Noted.

    Thank you for your assistance.

    #1170099

    Christian
    Moderator

    You’re welcome.