Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1336355
    Deepak
    Participant

    Is there a way to assign a custom sidebar to a custom post type? The custom post type/page doesn’t show up in “All Pages and Posts” or “All Taxonomies” checklist. I have assigned a category to the custom post type page which is shown in the “All Taxomonies” checklist but it doesn’t render in the front end.

    I have assigned a layout of Sidebar Left Content Right to this custom page and it does display as aside but an empty one.

    Any solution would be great as I have many posts that needs to be assigned a sidebar.

    Thanks in advance.

    #1336442
    Paul R
    Moderator

    Hi,

    To add sidebar, you can add this in your child theme’s functions.php

    
    function add_sidebar_custom_post() {
        if(  get_post_type() == 'custompost') {
            return 'sidebar-content';
        }
    }
    add_filter( 'x_option_x_layout_content', 'add_sidebar_custom_post' );
    

    Change custompost with your post type name.

    Hope that helps.

    #1336591
    Deepak
    Participant

    Hi Paul,

    Thanks for replying. I added the the code in my functions.php with my custom post called ‘catchment’ but nothing happened. The custom post didn’t appear in the list of checkboxes to assign the custom sidebar. What am I missing? Is ‘sidebar-content’ defined somewhere by X or this has to be customised? The main side bar show up with no problem but I would like to add custom sidebar.

    
    // ADD SIDEBAR TO CUSTOM POSTS
    // =============================================================================
    
    function add_sidebar_custom_post() {
        if(  get_post_type() == 'catchment') {
            return 'sidebar-content';
        }
    }
    add_filter( 'x_option_x_layout_content', 'add_sidebar_custom_post' );
    #1336621
    Deepak
    Participant

    This post gave me the answer – https://community.theme.co/forums/topic/category-specific-sidebar/#post-888152

    // ADD SIDEBAR TO CUSTOM POSTS
    // =============================================================================
    
    function add_sidebar_custom_post() {
        if(  get_post_type() == 'catchment') {
            return 'ups-sidebar-contact';
        }
    }
    add_filter( 'ups_sidebar', 'add_sidebar_custom_post' );

    Thanks for listening.

    #1336732
    Joao
    Moderator

    Thanks for letting us know,

    Cheers

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