- This topic has 5 replies, 3 voices, and was last updated 3 years, 3 months ago by Tom.
-
AuthorPosts
-
January 5, 2021 at 3:02 pm #1607221Scott
Hi,
I created a CPT using CPT UI plugin. I also created a template page to display the single CPT using the single.php as the template source.
How do you add a comment form to the bottom of a custom post type.
For example, I would like to add the same comment form at the bottom of this post:
https://sites.arizonabirdingtrail.com/hello-world/
to the bottom of this custom post type:
https://sites.arizonabirdingtrail.com/site/fountain-hills-lake/
thanks!
January 5, 2021 at 5:10 pm #1607306LeoStaffCustomer SupportHi there,
Give this solution a shot:
https://gist.github.com/davidperezgar/8b07e739b56b08e915581ae2e57d5766January 5, 2021 at 9:47 pm #1607429ScottHi,
Yes, I added a hook with those settings. This displays a link at the bottom of the single CPT, but the link doesn’t work.
The link is appending ‘#respond’ to the post title.
Should the comment form be loading in a pop up window, or inline?
You can view the ‘Leave a Comment’ link at the bottom of the post here:
https://sites.arizonabirdingtrail.com/site/fountain-hills-lake/-s
January 6, 2021 at 9:22 am #1608292TomLead DeveloperLead DeveloperHi there,
You would want to do something like this: https://github.com/tomusborne/generatepress/blob/3.0.2/inc/structure/comments.php#L177-L204
You’d just need to replace this condition:
if ( 'single' === $template || 'page' === $template ) {
With one for your CPT:
if ( is_singular( 'My Post Type' ) ) {
January 8, 2021 at 10:31 am #1611352ScottJust a followup in case others have a similar issue.
1) Created a custom post type single template by copying single.php -> single-cpt.php
2) Created a custom template by copying content-single.php -> content-cpt.php
In the file single-cpt.php, I had to replace the function call:
generate_do_template_part( 'single' );
with
get_template_part( 'content', ‘cpt’ );
When using the function get_template_part, the comment form was not rendered at the bottom of the single CPT post. Therefore, I added the following snippet to the end of content-cpt.php:
<?php generate_do_comments_template('single'); ?>
Correct me if I’m mistaken, but it appears that generate_do_template_part will load the comment form, but calling get_template_part, will not.
January 9, 2021 at 9:47 am #1612407TomLead DeveloperLead DeveloperThat’s correct, you would have to use
generate_do_template_part()
in order to use thegenerate_after_do_template_part
hook.Using
generate_do_comments_template( 'single' )
works as well 🙂 -
AuthorPosts
- You must be logged in to reply to this topic.