Comment function for page

时间:2018-01-14 作者:Per

我正在尝试加入我的评论。页面上的php和我的自定义注释函数不会返回任何结果(适用于帖子)。请帮我整理一下。

我希望能够创建一个ACF块来包含一个自定义注释块(但可以设置与页面上相同的样式)。

作用

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;
}
评论。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>

1 个回复
最合适的回答,由SO网友:Per 整理而成

我自己解决了这个问题。解决方案非常简单,只需调用注释模板即可。我想我最初两次调用模板就把事情搞砸了

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

结束

相关推荐

创建自定义HTML代码的Comments.php形式

一个示例comments.php 可用here.我已经创建了comments.php 我的主题文件夹中的文件。在我的content.php 用于显示评论表单的HTML如下所示:<textarea name=\"name\" rows=\"8\" cols=\"80\"></textarea> <div class=\"t-comment-section\"> <p>Full Name:</p> <i

Comment function for page - 小码农CODE - 行之有效找到问题解决它

Comment function for page

时间:2018-01-14 作者:Per

我正在尝试加入我的评论。页面上的php和我的自定义注释函数不会返回任何结果(适用于帖子)。请帮我整理一下。

我希望能够创建一个ACF块来包含一个自定义注释块(但可以设置与页面上相同的样式)。

作用

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;
}
评论。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>

1 个回复
最合适的回答,由SO网友:Per 整理而成

我自己解决了这个问题。解决方案非常简单,只需调用注释模板即可。我想我最初两次调用模板就把事情搞砸了

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