Sidebar not showing on specific category posts

Hey. I’d like to have a specific sidebar appear on certain categories and it’s not happening.

In this post, for example --> https://intothemythica.com/paia-once-more-parking-lot-of-the-gods/

Which is in the category ‘Peter Fae - From the Quest’

And I’ve linked (as far as I know, unless I made an error) this sidebar into it -->

So I am confused. It seems as though I am missing something or there is a conflict. I’d lie this sidebar to show up on all posts and pages which are part of the Peter Fae - From the Quest category

Hey Peter,

I’ve added an image widget to your sidebar and it works. It is your other widgets within the sidebar that doesn’t or aren’t configured correctly.

Hope that helps.

Notice this - A blog entry, in the category ‘From the Quest of Peter Fae’, which does not have the declared sidebar. What must I do to have the sidebar I have chosen appear on all the posts within a particular category?

https://intothemythica.com/2019-1-22-the-temple-and-the-path/

Hi Peter,

Assigning a sidebar to a category is only restricted to its category page and not for the post of that category.

Please check this https://theme.co/apex/forums/topic/customizing-blog-layout/?replyto=241840#post-241897, it would require custom code to achieve the setup you’re looking for :slight_smile:

Thanks!

I’m confused. That what does the ‘all taxonomies’ option on the sidebar relate to?

Also, that link doesn’t go to a page for me. I get ‘it does exist or was made private’, which is strange because it was viewable to me before, yet suddenly changed. I noticed a bunch of code that could have shifted the issue for me, yet now I can’t see the page.

Hi Peter,

That what does the ‘all taxonomies’ option on the sidebar relate to?

It’s for taxonomy page and not for post page, taxonomy page is where the listing is displayed.

I checked the provided URL and it’s not private, I can access it on incognito without logging in. Please check it again with another browser.

Thanks!

Okay that works in another browser. Would you please be a bit more specific?

Am I to put the code listed on that page in the child theme so as to get the effect I want with the sidebar relative to the category posts?

or am I to do the bit in “Then follow this …”

And THEN add in the second bit of code right below it? Confused as to what you’re sharing with me exactly

Hi Peter,

Yes, please follow the instruction provided on that thread. And yes, it should be added to the child theme’s functions.php. And please skip the Then follow this.

Then I’ll split the code to explain them bit by bit.

This part make sure the post has a sidebar regardless of chosen layout

if ( ! function_exists( 'x_get_content_layout' ) ) :
  function x_get_content_layout() {

    $content_layout = x_get_option( 'x_layout_content', 'content-sidebar' );

    if ( $content_layout != 'full-width' ) {
      if ( is_home() ) {
        $opt    = x_get_option( 'x_blog_layout', 'sidebar' );
        $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_category() ) {
      	$layout = 'content-sidebar';
      } elseif ( is_archive() ) {
        if ( x_is_shop() || x_is_product_category() || x_is_product_tag() ) {
          $opt    = x_get_option( 'x_woocommerce_shop_layout_content', 'sidebar' );
          $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
        } else {
          $opt    = x_get_option( 'x_archive_layout', 'sidebar' );
          $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', 'sidebar' );
        $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
      } elseif ( x_is_buddypress() ) {
        $opt    = x_get_option( 'x_buddypress_layout_content', 'sidebar' );
        $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
      } elseif ( is_404() ) {
        $layout = 'full-width';
      } else {
        $layout = $content_layout;
      }
    } else {
      $layout = $content_layout;
    }

    return $layout;

  }
endif;

This choose the sidebar for the post equal to the sidebar of its category

function ups_display_sidebar_v2( $default_sidebar ) {

  $q_object = get_queried_object();
  $sidebars = get_option( 'ups_sidebars' );

  foreach ( $sidebars as $id => $sidebar ) {
    if ( is_category() ) {
      
       $setting = get_option( "taxonomy_". $q_object->term_id );
       $default_sidebar = $setting['portfolio-category-sidebar'];

    }
  }

  return $default_sidebar;

}
add_filter( 'ups_sidebar', 'ups_display_sidebar_v2', 9999 );

But it’s not gonna work, what I provided is customization for portfolio category sidebar. Sorry about that, instead, please follow this https://theme.co/apex/forums/topic/create-sidebar-for-post-category/#post-196190. The URL I first provided has the code derived from that original code and just modified for portfolio.

It’s a bit long and it’s a complex implementation so it may not work on first try. Else, I recommend contacting a developer as I do understand that it’s a bit compled and hard.

Thanks!

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