Tagged: x
-
AuthorPosts
-
November 17, 2016 at 2:36 pm #1261513
michaelxxxParticipantHi,
I have an own attachment page for every picture, like:
How can I set an own sidebar only for attachment pages?
In the wordpress menu I can add sidebars only to pages, posts and taxonomies.
November 17, 2016 at 9:17 pm #1262031
Rue NelModeratorHello There,
Thanks for writing in! By default, the attachment page is a fullwidth page. To be able to have a sidebar, we need to customize the content layout. Since your child theme is set up, please add the following code in your child theme’s functions.php file
// Custom content layout to add a sidebar for the image attachment page // ============================================================================= 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; if ( is_attachment() ) { $layout = 'content-sidebar'; // use <code>sidebar-content</code> if you want to have a sidebar left content right 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; } return $layout; } // =============================================================================Now that we have modified the attachment page’s layout, we can now assign a sidebar. Again, please add the following code in your child theme’s functions.php file
// Assign a custom sidebar for image attachment pages // ============================================================================= add_filter( 'ups_sidebar', 'my_attachment_sidebar', 99999 ); function my_attachment_sidebar ( $sidebar ) { return is_bbpress() ? 'ups-sidebar-attachment' : $sidebar; } // =============================================================================Please make sure that you have assigned the correct ID of the sidebar like ‘ups-sidebar-ID’.
Hope this helps. Please let us know how it goes.
November 18, 2016 at 8:41 am #1262561
michaelxxxParticipantThis reply has been marked as private.November 18, 2016 at 2:16 pm #1262885
RadModeratorHi there,
Nope, or else it will override the entire sidebars on the whole site. Would you mind providing your FTP login credentials as well? Please replace this
// Assign a custom sidebar for image attachment pages // ============================================================================= add_filter( 'ups_sidebar', 'my_attachment_sidebar', 99999 ); function my_attachment_sidebar ( $sidebar ) { return is_bbpress() ? 'ups-sidebar-attachment' : $sidebar; } // =============================================================================with this
// Assign a custom sidebar for image attachment pages // ============================================================================= add_filter( 'ups_sidebar', 'my_attachment_sidebar', 99999 ); function my_attachment_sidebar ( $sidebar ) { return x_is_bbpress() ? 'ups-sidebar-attachment' : $sidebar; } // =============================================================================Thanks!
November 18, 2016 at 4:47 pm #1263020
michaelxxxParticipantThis reply has been marked as private.November 18, 2016 at 11:48 pm #1263348
Rue NelModeratorHello There,
Thank you for the clarifications! Sorry, there was a wrong condition. My big apology for the mistake I made in the code. The code block should be this:
// Assign a custom sidebar for image attachment pages // ============================================================================= add_filter( 'ups_sidebar', 'my_attachment_sidebar', 99999 ); function my_attachment_sidebar ( $sidebar ) { return is_attachment() ? 'ups-sidebar-brasilien' : $sidebar; } // =============================================================================Please let us know if this works out for you.
November 19, 2016 at 3:28 am #1263469
michaelxxxParticipantThis reply has been marked as private.November 19, 2016 at 3:51 am #1263483
ChristopherModeratorHi there,
Please add following code in Customize -> Custom -> Global CSS :
@media (min-width:979px){ .attachment .offset.cf { float: left; width: 74%; } body.x-navbar-fixed-top-active .x-navbar-wrap { height: auto; } }Hope that helps.
November 19, 2016 at 6:22 am #1263552
michaelxxxParticipantThis reply has been marked as private.November 19, 2016 at 5:04 pm #1263823
RadModeratorHi there,
It looks the same on big screen and smaller screen on my end. But in mobile, the sidebar break under and it’s only normal. Would you mind clarifying what part of the screenshot has the issue? Because it looks the same whichever the size of my screen/browser.
The code for the layout is only to enable sidebar placeholder, if you already had the sidebar enabled globally then the code has no use at all. But given that it has a sidebar now, then I think it should be okay.
Thanks!
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1261513 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
