• Resolved gahia

    (@gahia)


    Hi!

    I would like to know the best way to make a custom post type works with Twentig.

    My case is simple. I have a custom post type that acts like a post and I can extend Twenty Twenty cover template to work with it but I need it gets also all the Twentig customization for blog posts (like Post Cover Height).

    What’s the way to make it happen?

    Thanks for the plugin, it is awesome!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Twentig

    (@twentig)

    Hi,

    Thanks for your message.

    Assuming that you’ve created your own plugin or child theme (to create your CPT), you can add the following PHP code in one of your PHP files. Replace 'post_type' with your post type name.

    function my_custom_body_class( $classes ) {
    	if ( is_singular( 'post_type' ) ) {
    		$cover_height = get_theme_mod( 'twentig_cover_post_height' );
    		if ( $cover_height ) {
    			$classes[] = 'tw-cover-' . $cover_height;
    		}
    		if ( 'center' === get_theme_mod( 'twentig_cover_vertical_align' ) ) {
    			$classes[] = 'tw-cover-center';
    		}
    	}
    	return $classes;
    }
    add_filter( 'body_class', 'my_custom_body_class', 12 );

    I hope the above is useful to you.
    If you enjoy Twentig, please leave us a review ??

    Thread Starter gahia

    (@gahia)

    I understand, I should replicate the Twentig code for my custom types… Fair enough.

    Hope in the future Twenty can handle it and allow to enable its overrides to custom post types.

    Thanks for the reply!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom post type templates’ is closed to new replies.