Tagged: x
-
AuthorPosts
-
June 6, 2016 at 9:20 am #1028056
GhostWhaleParticipantHi,
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
June 6, 2016 at 9:25 am #1028066
GhostWhaleParticipantThis reply has been marked as private.June 6, 2016 at 10:47 am #1028188
RahulModeratorHi There,
Please make sure you have chosen one of content’s layout with sidebar under Customize -> Stack.
Check the screen shot : http://prntscr.com/5lr8j9Thank you.
June 6, 2016 at 1:00 pm #1028427
GhostWhaleParticipantYes 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?
June 6, 2016 at 9:22 pm #1029141
RadModeratorHi 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!
June 7, 2016 at 2:44 pm #1030511
GhostWhaleParticipantDoing 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
June 8, 2016 at 1:59 am #1031358
Paul RModeratorHi,
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 credentialsDon’t forget to select Set as private reply. This ensures your information is only visible to our staff.
June 16, 2016 at 5:07 pm #1045972
GhostWhaleParticipantHi 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
June 16, 2016 at 9:39 pm #1046381
LelyModeratorHi 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.
June 17, 2016 at 3:07 am #1046669
GhostWhaleParticipantLooks like that’s done the trick.
Many Thanks
June 17, 2016 at 3:10 am #1046677
Rue NelModeratorYou’re welcome!
Thanks for letting us know that it has worked for you.October 3, 2016 at 6:15 am #1200336
pylonParticipantIs 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?
October 3, 2016 at 7:00 am #1200379
Paul RModeratorHi,
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.
October 3, 2016 at 9:38 am #1200516
pylonParticipantPaul
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)?
October 3, 2016 at 10:56 pm #1201453
LelyModeratorHi 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.
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1028056 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
