- This topic has 12 replies, 4 voices, and was last updated 3 years, 6 months ago by
David.
-
AuthorPosts
-
June 19, 2021 at 3:36 am #1827377
ilie
Hello,
On the support page here:
https://docs.generatepress.com/article/setting-up-a-simple-custom-post-type/Step 3, is not working.
Changing that line from:
generate_do_template_part( 'single' );To
generate_do_template_part( 'project' );Results in an empty page…
The only way I can get the new templates to work is to change it to this instead:
get_template_part( 'content', 'project' );If you look inside the ‘generate_do_template_part’ helper function, it will completely ignore anything but the standard template parts. So is the documentation outdated? Or am I doing something wrong here?
June 19, 2021 at 3:37 am #1827378ilie
These old tickets seem to have the same solution as I found, which means the documentation needs to be updated to reflect the source code.
https://generatepress.com/forums/topic/custom-post-type-template/
https://generatepress.com/forums/topic/custom-post-type-template/June 19, 2021 at 8:11 pm #1828024Tom
Lead DeveloperLead DeveloperHi there,
Thanks for the heads up, I just updated the article.
Let us know if you have any other questions 🙂
September 2, 2022 at 5:11 pm #2331988Burke
I’m having the same problem as ilie. The only way I can make anything show up on the page is if, in single-mycpt.php I use:
get_template_part( ‘content’, ‘mycpt’ );
Otherwise it’s just blank nothingness – neither the post content nor anything in content-mycpt.php is appearing on the page.
However, I need to change the whole template. Please advise.
September 3, 2022 at 3:05 am #2332220David
StaffCustomer SupportHi there,
so are you not wanting a
content-mycpt.php?September 3, 2022 at 3:20 am #2332231Burke
I want the best option to make all of the Generateblocks work properly. What I will probably do is use a
single-mycpt.php, keepgenerate_do_template_part( 'single' );in it, and useif ('mycpt' !== get_post_type())...where I have to.I really wish I could keep all of my headers and content completely separate from content-single.php though. This seems like something Generatepress should make easier for us.
September 4, 2022 at 1:32 pm #2333316David
StaffCustomer SupportSo GP does handle that.
You have the Single template, which contains the Loop and the stuff outside the loop, e.g Header , Footer and other hooks.
Then the Content template which is litterally just the container for your post content.I am not sure what the issue is. Can you explain a little on what you want to achieve ?
September 4, 2022 at 2:48 pm #2333339Burke
I figured out some things on my own, but this is what is happening:
1. My custom post type is ‘winery’.
2. In my child theme I copied over
single.phpandcontent-single.php3. I renamed the two files
single-winery.phpandcontent-winery.phpAt this point the custom post type and the comments section are showing up fine with the wysiwyg text (i.e. the_content()) appearing on the custom post.
4. I change the line
generate_do_template_part( 'single' );togenerate_do_template_part( 'winery' );and boththe_content()and the comments section disappear.5. If I replace
generate_do_template_part( 'winery' );withget_template_part( 'content', 'winery' );thenthe_content()appears but not the comments section.I’m using MAMP locally and have to refresh once or twice for things to appear correctly – that was the source of my original confusion.
But, why did the comments section disappear? And what is the difference beteen
generate_do_template_partandget_template_part?September 5, 2022 at 6:21 am #2333800David
StaffCustomer SupportAh ok. To cover:
generate_do_template_partis a function we implemented so you could hook in your own templates without the need for child themes. It’s what we use for the Block Element – Content Template.You can see the function here:
if the $template matches the core templates it returns a
get_template_partcallback.
It also has its own before >generate_before_do_template_partand after >generate_after_do_template_parthooks.And the latter one is where we call the comments template:
So this does introduce choices.
You can either:
1. The traditional child theme methods and use
get_template_part( 'content', 'winery' );
You will need to hook in the<?php generate_do_comments_template('single'); ?>in your content template.2. Use the
generate_do_template_partcallback, and then you can do something like this:// Disable the core template part add_filter( 'generate_do_template_part', function( $do ) { if ( is_singular('winery') ) { return false; } return $do; } ); // Hook in your own template. add_action( 'generate_before_do_template_part', function() { if ( is_singular('winery') ) { get_template_part( 'content', 'winery' ); } } );The latter method, probably makes more sense if you want to use the Block Element – Content template or take advantage of the extra GP hooks
September 5, 2022 at 7:52 am #2334015Burke
So do I just put that big section of code you provided into single-winery.php instead of (replacing)
generate_do_template_part( 'winery' );?I did that and the page is all still blank.
September 5, 2022 at 8:08 am #2334037David
StaffCustomer SupportSo you did this:
2. In my child theme I copied over single.php and content-single.php
3. I renamed the two files single-winery.php and content-winery.php
At that point you would still have the original
generate_do_template_part( 'single' );in your single-winery template.
You can leave that as is.And then the code i provided you add to your functions.php.
September 5, 2022 at 8:13 am #2334039Burke
Perfect. That did it. Thank you!
September 5, 2022 at 8:37 am #2334054David
StaffCustomer SupportYou’re welcome – thanks for your patience. Its something we need to make a little clearer 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.