[Support request] Add Comment Form To Custom Post Type

Home Forums Support [Support request] Add Comment Form To Custom Post Type

Home Forums Support Add Comment Form To Custom Post Type

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1607221
    Scott

    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!

    #1607306
    Leo
    Staff
    Customer Support
    #1607429
    Scott

    Hi,

    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

    #1608292
    Tom
    Lead Developer
    Lead Developer

    Hi 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' ) ) {

    #1611352
    Scott

    Just 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.

    #1612407
    Tom
    Lead Developer
    Lead Developer

    That’s correct, you would have to use generate_do_template_part() in order to use the generate_after_do_template_part hook.

    Using generate_do_comments_template( 'single' ) works as well 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.