Archived topic
Need help Creating CPT file (single and archive). Thanks.
3 replies · Started by Martin on August 28, 2021
Hi there.
I've been going through a number of posts relating to Custom Post types file and as most relate to each person's individual needs I haven't managed to get the answer I'm looking for.
With other WP themes (inc custom made from scratch themes) I have simply duplicated singe.php and replaced the main content section with content and loop for the CPT but when I remove the loop in the CPT single (duplicate of single.php) I also lose the CSS associated with the body / artic section.
if ( generate_has_default_loop() ) {
while ( have_posts() ) :
the_post();
generate_do_template_part( 'single' );
endwhile;
}
Could you point out what I'm doing wrong please and what parts of single-custompost.php, archive-custompost.php and taxonomy-customtax.php I need to keep?
Thanks.
Martin
Hi there,
Starting within the single.php - this line is the only one i would change if i want maintain the theme layout and styles:
And this docs what to change it to, to point to your single-content
https://docs.generatepress.com/article/setting-up-a-simple-custom-post-type/
And again on the single-content template, i would keep all the markup and just work around the_content function:
The same logic applies for the Archives.php.
Thank you David.
That's a great start.
You're welcome.