Different Sidebar for Post and Portfolio

Hi there

I wonder if its possible to have a different sidebar for the post index page and the portfolio index page.

The difference between the sidebar should be the content:
i.e Sidebar for post index page should show latest posts, latest comments in posts, posts archive and posts category. Whereas the sidebar for portfolio page should show latest portfolio items, latest comments in portfolio items, portfolio items archive and portfolio categories.

I already created a portfolio sidebar but I do know how to configure it to manage the above differntiation and assignment.

Can you help?

Best regards, Ruedi

Hi there,

Thanks for writing in.

You can create multiple sidebars in Admin > Appearance > Sidebars and assign them to your post or portfolio. Then simply add your widgets through Admin > Appearance > Widgets to your created sidebars.

Thanks!

Hi Rad, yes this is clear and I already created such different sidebars.
I currently using the “Integrity” stack.
My posts are shown on the page “/neuigkeiten” with the assigned sidebar --> everything fine
My portfolio posts are shown on the page “/projekte” where the site attribute Template is set to “Layout-Portfolio”. This template is neccessary to get the index of all different posts related to projects (portfolio-items).
When I change the template to “Layout - Content left, sidebar right)” the assigned sidebar is shown but there is no index of the different portfolio-items.

The second problem is that it seems to be impossible to only list the portfolio-items because there is only a widget for posts and latest posts but not for portfolio-items.

Is there any solution for the two problems?

Best regards, Ruedi

Oh, by the way, the page I’m talking about is
www.strahlexpert.ch

Hi,

  1. To add sidebar to portfolio layout

You can try adding the code below in your child theme functions.php file.

function add_sidebar_portfolio($layout) {  
    if(x_is_portfolio()) {      
       $layout = "content-sidebar";
   }
  return $layout;
}
add_filter('x_option_x_layout_content', 'add_sidebar_portfolio',999);
  1. You can use the recent post shortcode type=portfolio

http://demo.theme.co/integrity-1/shortcodes/recent-posts/

Hope that helps

Dear Paul, thanks for the try but this is not working.
I understand to leave the Page-Attribute of the portfolio index page (which is named „Projekte“) on „Layout - Portfolio“. I added your code into „functions.php“ (child-theme) and checked the name of my separate sidebar if it is named „sidebar_portfolio“. Nevertheless no sidebar is shown.

The second question was misunderstood (I guess). I want to show up the latest portfolio items on the sidebar instead of the standard blog posts. When defining a sidebar, different widgets can be set together, but there is no widget for Portfolio-items.

Any idea?

Best regards, Ruedi

Hi Ruedi,

  1. Yes that’s correct. Please try this code instead.
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() ) {
        $layout = 'content-sidebar';
      } 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;
  }
  1. You can add the recent post shortcode in a text widget.

eg.


[recent_posts count="2" orientation="vertical" type="portfolio"]

By setting type=“portfolio”, it will display portfolio items instead of post.

If none of this work, please provide wordpress admin login in Secure Note

Thanks

1 Like

it work like a charme, thank for your help

you are welcome!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.