Archived topic
Add custom layouts to custom post type single pages
3 replies · Started by Tom on April 11, 2022
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
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' );
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
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' );