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!