Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1028056
    GhostWhale
    Participant

    Hi,

    I have a sidebar which I’d like to appear on all posts by default. It’s annoying having to go into the dashboard>appearance>sidebars menu and tick the new post once published to make the sidebar appear.

    Is there a way of doing this?

    Thanks

    #1028066
    GhostWhale
    Participant
    This reply has been marked as private.
    #1028188
    Rahul
    Moderator

    Hi There,

    Please make sure you have chosen one of content’s layout with sidebar under Customize -> Stack.
    Check the screen shot : http://prntscr.com/5lr8j9

    Thank you.

    #1028427
    GhostWhale
    Participant

    Yes I’ve done that. Customize -> Layout & Design, it’s set to Content Left, Sidebar Right. The problem is that I’ve created a sidebar but to get it to appear on a post I have to go to dashboard>appearance>sidebars and then check the box for the relevant post(s) that I want it to appear on.

    I want it to appear on all posts but not on any pages. Each new blog post I do, I just want the same sidebar to appear without having to go and check the box each and every time. Is there a way to make sure all new posts have the sidebar appear by default?

    #1029141
    Rad
    Moderator

    Hi there,

    Please add this code to your child theme’s functions.php with your Sidebar ID created at Admin > Appearance > Sidebars

    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;
    
      }
    
    add_filter( 'ups_sidebar', 'custom_ups_display_sidebar', 999 );
    
    function custom_ups_display_sidebar ( $sidebar ) {
    
    return is_singular('post') ? 'YOUR-SIDEBAR-ID-HERE' : $sidebar;
    
    }
    
    

    Cheers!

    #1030511
    GhostWhale
    Participant

    Doing this just killed the site with a fatal error. Probably because I put this in immediately following the attached php (which is to ensure the sidebar appeared on all search results pages as per your support on another thread). Can you advise the correct php code to the same sidebar to appear on all search results pages AND all new posts.

    Thanks

    #1031358
    Paul R
    Moderator

    Hi,

    Would you mind providing us with login credentials so we can take a closer look? To do this, you can make a post with the following info:

    – Link to your site
    – WordPress Admin username / password
    – FTP credentials

    Don’t forget to select Set as private reply. This ensures your information is only visible to our staff.

    #1045972
    GhostWhale
    Participant

    Hi Paul,

    I’ve just noticed my attachment didn’t work as the file type wasn’t allowed.

    I have already input the PHP code supplied in the following thread into my functions.php file: https://community.theme.co/forums/topic/how-to-customise-formatting-of-search-results/

    It works perfectly for making the sidebar appear on search results page as requested. Please can you advise on the code I need to REPLACE this with in order to have the same sidebar appear on search results page AND all posts pages.

    Thanks

    #1046381
    Lely
    Moderator

    Hi There,

    Glad it is working for you. In order to show the same sidebar on single post pages, please update to this:

    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_search() || is_singular( 'post' )) {
          $layout = 'content-sidebar';
        }
    
        return $layout;
    
      }
    
    add_filter( 'ups_sidebar', 'custom_ups_display_sidebar', 999 );
    
    function custom_ups_display_sidebar ( $sidebar ) {
    
    if(is_search() || is_singular( 'post' )){
    return 'YOUR-SIDEBAR-ID-HERE';
    }
    
    }

    Hope this helps.

    #1046669
    GhostWhale
    Participant

    Looks like that’s done the trick.

    Many Thanks

    #1046677
    Rue Nel
    Moderator

    You’re welcome!
    Thanks for letting us know that it has worked for you.

    #1200336
    pylon
    Participant

    Is this the correct, recognised way to add a common, default sidebar to all posts currently? Seems bizarre for such an advanced theme like X to have functions.php addition to accomplish it.

    Can themeco please confirm, or is this covered by an update since v4.3.0 which I’m currently on?

    #1200379
    Paul R
    Moderator

    Hi,

    You can usually achieve that by selecting a Content Layout with a sidebar under Layout and Design in the customizer

    http://screencast.com/t/Pb6Jp1OIpVJv

    Then set your Blog to use the Content Layout.

    http://screencast.com/t/YM4ZRKqt

    But if you have set your content Layout as Fullwidth, the code provided above is necessary so you can have a sidebar in your posts.

    Hope that makes sense.

    #1200516
    pylon
    Participant

    Paul

    Thanks for confirming.

    I have both those options enabled from the beginning. But that still doesn’t allow us to choose WHICH sidebar we have on all posts. It simply Assigns ‘Main Sidebar’.

    OK, we can work around this by filling Main Sidebar with widgets we want displayed on all posts, but this sidebar is also used by default for pages too, where we might not want ‘post’ related widgets.

    I wanted a separate sidebar for my Blog Index page to the rest of the posts. I thought you may be able to assign a globAL Sidebar to posts in the Appearance > Sidebars area. Am I missing a trick here (or are Themeco)?

    #1201453
    Lely
    Moderator

    Hi There,

    When we choose Content Layout with Sidebar on Layout and Design, this by default will add sidebar on blog index pages, archive pages and single post pages. The content of the sidebar are widgets you have added on Appearance >Widgets > Main Sidebar. On pages, when you select Template with sidebar, the content of the same Main Sidebar will show too. On the other hand, when we create custom sidebar on Appearance > Sidebar, this will only show on pages or post the we specified.

    I wanted a separate sidebar for my Blog Index page to the rest of the posts.

    To achieve that, no need to add custom code. Just add custom sidebar on Appearance > Sidebar and then on Blog Display check this option. This will display your custom sidebar instead and your single post page will display the normal main sidebar.

    Hope this helps.

  • <script> jQuery(function($){ $("#no-reply-1028056 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>