[Resolved] Different layouts for different custom post types

Home Forums Support [Resolved] Different layouts for different custom post types

Home Forums Support Different layouts for different custom post types

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #210509
    Dhruv

    Hello Sir

    I have 2 custom post types (Notes and Downloads) in my website.
    How can I set different layouts for its single.php posts.

    In notes post type I want layout like
    Sidebar/content

    While in downloads post type I want layout like
    content/sidebar

    Kindly suggest me any code for getting this functionality.

    Thanks

    #210610
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    You can use our sidebar filter:

    add_filter( 'generate_sidebar_layout','generate_custom_sidebar_layout' );
    function generate_custom_sidebar_layout( $layout )
    {
     	if ( is_post_type_archive( 'downloads' ) )
     	 	return 'right-sidebar';
    
     	if ( is_post_type_archive( 'notes' ) )
     	 	return 'left-sidebar';
    
     	// Or else, set the regular layout
     	return $layout;
    
     }

    Adding PHP: http://generatepress.com/knowledgebase/adding-php-functions/

    #210715
    Dhruv

    Hi..
    Thank you for support.

    I have copied the code in functions.php

    But it is not working. It is not changing default layout set in customiser.

    Regards

    #210722
    Tom
    Lead Developer
    Lead Developer

    That code won’t do anything to the Customizer, it will just change the sidebar layout on the “notes” and “downloads” post type archives.

    Make sure the post types are named “notes” and “downloads” specifically – if they’re different then those names need to change.

    #212227
    Dhruv

    Hello Tom,

    Actually I wanted the sidebars on singular pages of custom post types.
    So, I just changes the code from is_post_type_archives() to is_singular() and it is working now.

    add_filter( 'generate_sidebar_layout','generate_custom_sidebar_layout' );
    function generate_custom_sidebar_layout( $layout )
    {
     	if ( is_singular( $post_types = 'download' ) )
     	 	return 'right-sidebar';
    
    if ( is_singular( $post_types = 'notes' ) )
     	 	return 'left-sidebar';
    
    	// Or else, set the regular layout
     	return $layout;
    
     }

    Thanks for Guiding…This issue is resolved ๐Ÿ™‚

    #212282
    Tom
    Lead Developer
    Lead Developer
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.