Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1261513
    michaelxxx
    Participant

    Hi,

    I have an own attachment page for every picture, like:

    http://one-million-places.com/reiseberichte/asien/china/hong-kong/aussicht-auf-hong-kong-vom-victoria-peak/attachment/the-peak-bilder-019

    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.

    #1262031
    Rue Nel
    Moderator

    Hello 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.

    #1262561
    michaelxxx
    Participant
    This reply has been marked as private.
    #1262885
    Rad
    Moderator

    Hi 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!

    #1263020
    michaelxxx
    Participant
    This reply has been marked as private.
    #1263348
    Rue Nel
    Moderator

    Hello 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.

    #1263469
    michaelxxx
    Participant
    This reply has been marked as private.
    #1263483
    Christopher
    Moderator

    Hi 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.

    #1263552
    michaelxxx
    Participant
    This reply has been marked as private.
    #1263823
    Rad
    Moderator

    Hi 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!

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