0

I'm trying to include my comments.php on a page and my custom comment function isn't returning any result (works on posts). Please help me sort this.

I want to be able to create a ACF block to include a custom comment block (but can be styled the same as on pages).

Function

function zeuligan_comment($comment, $args, $depth) {
if ( 'div' === $args['style'] ) {
    $tag       = 'div';
    $add_below = 'comment';
} else {
    $tag       = 'li ';
    $add_below = 'div-comment';
}?>
<<?php echo $tag; comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?> id="comment-<?php comment_ID() ?>"><?php 
if ( 'div' != $args['style'] ) { ?>
    <div id="div-comment-<?php comment_ID() ?>" class="comment-body"><?php
} ?>
    <div class="comment-author vcard"><?php 
        if ( $args['avatar_size'] != 0 ) {
            echo get_avatar( $comment, $args['avatar_size'] ); 
        }; ?>
    </div><?php 
    if ( $comment->comment_approved == '0' ) { ?>
        <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></em><br/><?php 
    } ?>
    <div class="comment-content">
    <?php printf( __( '<cite class="fn">%s</cite>' ), get_comment_author_link() ); ?>
    <div class="comment-meta commentmetadata">
        <a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ); ?>"><?php
            printf( 
                __('%1$s at %2$s'), 
                get_comment_date(),  
                get_comment_time() 
            ); ?>
        </a><?php 
        edit_comment_link( __( '(Edit)' ), '  ', '' ); ?>
    </div>
    <?php comment_text(); ?>
    <div class="reply"><?php 
            comment_reply_link( 
                array_merge( 
                    $args, 
                    array( 
                        'add_below' => $add_below, 
                        'depth'     => $depth, 
                        'max_depth' => $args['max_depth'] 
                    ) 
                ) 
            ); ?>
    </div>
    </div>

<?php 
    if ( 'div' != $args['style'] ) : ?>
        </div><?php 
    endif;
}

the comments.php

<?php if ( post_password_required() ) { return; } ?>
<div id="comments" class="comments-area">
    <?php
    if ( have_comments() ) : ?>
        <h2 class="comments-title">
            <?php
            $comments_number = get_comments_number();
            if ( '1' === $comments_number ) {
                printf( _x( 'One Reply to &ldquo;%s&rdquo;', 'comments title', 'zeuligan' ), get_the_title() );
            } else {
                printf(
                _nx(
                    '%1$s Reply to &ldquo;%2$s&rdquo;',
                    '%1$s Replies to &ldquo;%2$s&rdquo;',
                    $comments_number,
                    'comments title',
                    'zeuligan'
                ),
                number_format_i18n( $comments_number ),
                get_the_title()
            );
        }
        ?>
        </h2>

        <ul class="comment-list">
            <?php
                wp_list_comments( array(
                    'avatar_size' => 100,
                    'style'       => 'ul',
                    'callback'    => 'zeuligan_comment',
                    'short_ping'  => true,
                    'reply_text'  => 'Reply',
                ) );
            ?>
        </ul>

            <?php the_comments_pagination( array(
                'prev_text' => '<span class="screen-reader-text">' . __( 'Previous', 'zeuligan' ) . '</span>',
                'next_text' => '<span class="screen-reader-text">' . __( 'Next', 'zeuligan' ) . '</span>',
            ) );

        endif;

        if ( ! comments_open() && get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) : ?>
            <p class="no-comments"><?php _e( 'Comments are closed.', 'zeuligan' ); ?></p>
        <?php
        endif;
        comment_form();
        ?>
    </div>
3
  • does the commenting work on a page without your custom code? with other words, does your theme allow and show comments on pages?
    – Michael
    Jan 14 '18 at 19:21
  • It is I who has build the theme from scratch and it's my first time coding, so might be hard to answer :) I checked the box for comments in admin for the specific page. I can get the form to show, but can't get actual comments to show on the page (but on posts).
    – Per
    Jan 15 '18 at 21:27
  • Figured it out, think I complicated matters and called the same template twice. Adding the code <?php if ( comments_open() || get_comments_number() ) { comments_template(); } to my ACF block worked
    – Per
    Jan 16 '18 at 15:15
0

Managed to solve this my self. The solution was as simple to just call the comments template. Think I originally messed up by calling the template twice

        if ( comments_open() || get_comments_number() ) {
            comments_template();
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.