Archived topic
Which Generatepress template to use for a custom post type loop?
5 replies · Started by Daniel on October 26, 2020
Hi!
I have a CPT created with the CPT UI plugin and I want to display a custom loop on one of the pages of my website.
Which generatepress page template do I have to copy into my child theme to modify it and add the custom loop?
I tried with page.php modifying from line 29 but I get a critical error.
I'm starting with this kind of programming to learn and I just need guidance on which generatepress template is better to use to include a custom loop.
I'm using GeneratePressVersion: 3.0.2
Thanks
Daniel
Hi there,
If this is for the single post type - then you should use the single.php:
https://github.com/tomusborne/generatepress/blob/master/single.php
For reference:
https://developer.wordpress.org/themes/template-files-section/custom-post-type-template-files/
Thanks David!
It isn't for the single post type but for displaying the loop of my CPT. I mean I need a page template where I'm going to paste my custom loop which will be something like:
<?php
$portafolio = new WP_Query( $args );
while ( $portafolio->have_posts() ) :
$portafolio->the_post();
generate_do_template_part( 'page' );
endwhile;
?>
I've tried modifiying with a copy of page.php called page-portfolio.php in my child theme and I have modified this section https://github.com/tomusborne/generatepress/blob/master/page.php#L29-L36
But it didn't work, maybe is my code which is incorrect, but I need to be sure if the template I have to modify is page.php or another.
Hi there,
You would need to replace the following line with your custom loop:
generate_do_template_part( 'page' );
The above line is a wrapper for this: get_template_part( 'content', 'page' );
So it's loading the content-page.php file in that place of your template.
Thank you Tom!
That was the little push I needed to make it work.
Awesome, glad I could help :)