[Support request] Add custom layouts to custom post type single pages

Home Forums Support [Support request] Add custom layouts to custom post type single pages

Home Forums Support Add custom layouts to custom post type single pages

  • This topic has 3 replies, 2 voices, and was last updated 4 months ago by Ying.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2185361
    Tom

    Hi,
    I’ve got a couple CPTs that require some custom code on each page,
    For each CPT I’ve followed https://docs.generatepress.com/article/setting-up-a-simple-custom-post-type/
    Taking Newsletters as an example, I’ve created a content-newsletters.php and single-newsletters.php to a child theme, and updated line 28 to be `generate_do_template_part( ‘newsletter’ );
    //get_template_part( ‘content’, ‘newsletter’ ); – commented out as another forum post updated this`

    I’ve added some code to the content-newsletter.php above the entry-content div, however it’s not showing on the page. Any suggestions for getting the code to show? (for now it’s just some text, but will be a video player and PDF embed)

    Thanks
    Tom

    #2185419
    Ying
    Staff
    Customer Support

    Hi Tom,

    and updated line 28 to be `generate_do_template_part( ‘newsletter’ );
    //get_template_part( ‘content’, ‘newsletter’ ); – commented out as another forum post updated this`

    Not fully understand what commented out as another forum post updated this this means.

    In thesingle-newsletter.php file, you should replace generate_do_template_part( 'single' ); with get_template_part( 'content', 'newsletter' );

    #2185560
    Tom

    Hi Ying,
    Thanks for your response, and apologies, reading back it didn’t make too much sense!

    I’ve un-commented that line, and removed the generate_do_template_part( ‘newsletter’ );, so my file now looks like this.
    Lines 24-31:

    if ( generate_has_default_loop() ) {
    				while ( have_posts() ) :
    
    					the_post();
    					get_template_part( 'content', 'newsletter' );
    
    				endwhile;
    			}

    However it’s still not displaying the code I’ve added to content-newsletter.php,

    Thanks,
    Tom

    #2185607
    Ying
    Staff
    Customer Support

    Taking Newsletters as an example, I’ve created a content-newsletters.php and single-newsletters.php

    It seems you have an s after newsletterin your file name. If that’s the case, there should be an s as well:
    get_template_part( 'content', 'newsletters' );

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.