启用主题中的嵌套注释

时间:2014-05-03 作者:HannesH

我试图在我的主题中启用嵌套注释。我对所有这些东西都是新手,但我正在尽全力。这是我在评论中的代码。php

<?php if ( get_comment_pages_count() > 1 && get_option( \'page_comments\' ) ) : // are there comments to navigate through ?>
    <nav id="comment-nav-above" class="comment-navigation" role="navigation">
        <h1 class="screen-reader-text"><?php _e( \'Comment navigation\', \'triday\' ); ?></h1>
        <div class="nav-previous"><?php previous_comments_link( __( \'← Older Comments\', \'triday\' ) ); ?></div>
        <div class="nav-next"><?php next_comments_link( __( \'Newer Comments →\', \'triday\' ) ); ?></div>
    </nav><!-- #comment-nav-above -->
    <?php endif; // check for comment navigation ?>

    <ol class="comment-list">
        <?php
            /* Loop through and list the comments. Tell wp_list_comments()
             * to use triday_comment() to format the comments.
             * If you want to override this in a child theme, then you can
             * define triday_comment() and that will be used instead.
             * See triday_comment() in inc/template-tags.php for more.
             */
            wp_list_comments( array( \'callback\' => \'triday_comment\' ) );
        ?>
    </ol><!-- .comment-list -->

    <?php if ( get_comment_pages_count() > 1 && get_option( \'page_comments\' ) ) : // are there comments to navigate through ?>
    <nav id="comment-nav-below" class="comment-navigation" role="navigation">
        <h1 class="screen-reader-text"><?php _e( \'Comment navigation\', \'triday\' ); ?></h1>
        <div class="nav-previous"><?php previous_comments_link( __( \'← Older Comments\', \'triday\' ) ); ?></div>
        <div class="nav-next"><?php next_comments_link( __( \'Newer Comments →\', \'triday\' ) ); ?></div>
    </nav><!-- #comment-nav-below -->
    <?php endif; // check for comment navigation ?>

<!--</div>-->
<?php endif; // have_comments() ?>
这是我用来显示注释的代码

<div class="comment-author">
                                <h3><i class="fa fa-user"></i><?php print(\' \')?><?php comment_author( $comment_ID ); ?></h3>
                        </div>
                                <?php if ( \'0\' == $comment->comment_approved ) : ?>
                                <div class="alert alert-danger">
                                    <p class="comment-awaiting-moderation"><?php _e( \'Your comment is awaiting moderation.\', \'triday\' ); ?></p>
                                </div>

                                <?php endif; ?>
                        <div class="comment-content">
                            <?php comment_text(); ?>
                        </div><!-- .comment-content -->
                            <div class="comment-metadata">
                                <a>comment_ID ) ); ?>">
                                    <time datetime="<?php comment_time( \'c\' ); ?>">
                                        <p class="text-muted"><i class="fa fa-calendar"> </i> <?php printf( _x( \'%1$s at %2$s\', \'1: date, 2: time\', \'triday\' ), get_comment_date(), get_comment_time() ); ?></p>
                                    </time>
                                </a>

                                <?php edit_comment_link( __( \'Edit\', \'triday\' ), \'<span class="edit-link">\', \'</span>\' ); ?>
                            </div><!-- .comment-metadata -->
                            <footer class="comment-meta">
                        </footer><!-- .comment-meta -->
                        <?php
                            comment_reply_link( array_merge( $args, array(
                                \'add_below\' => \'div-comment\',
                                \'depth\'     => $depth,
                                \'max_depth\' => $args[\'max_depth\'],
                                \'before\'    => \'<div class="reply">\',
                                \'after\'     => \'</div>\',
                            ) ) );
                        ?>
如果你能看看我做了什么,我真的很高兴!汉内斯

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

Settings >> Discussion Screen, 有一个选项勾选框,“启用线程(嵌套)注释[X]深度”。从那里,您可以勾选以激活线程注释,并将深度设置为最多10级。

您还应该检查您的主题是否有以下代码,通常应该在函数中。主题的php模板。

wp_enqueue_script(\'comment-reply\')
这将使脚本排队以正确显示线程注释。我引用了法典

请注意,需要对主题进行特殊编码,以正确显示线程注释。

如果找不到,只需将以下代码添加到函数中即可。php将此脚本排队。请注意,此脚本默认包含在Wordpress核心中,因此无需亲自查看或添加脚本。

function enable_threaded_comments(){
if (!is_admin()) {
     if (is_singular() && comments_open() && (get_option(\'thread_comments\') == 1))
          wp_enqueue_script(\'comment-reply\');
     }
}

add_action(\'get_header\', \'enable_threaded_comments\');
(代码来自paulund.co.uk)

EDIT

您的代码中有几个错误。我已经测试了您的第一组代码。出现语法错误

分析错误:语法错误,C:\\xampp\\htdocs\\wordpress\\wp content\\themes\\pietergoosen2014\\comments中出现意外的T\\u ENDIF。php在线30

这意味着你有一个额外的endif;, 所以把它去掉

在你的评论中,你问

你知道为什么我按下回复链接时会得到一个id吗,就像这样-

http://localhost:8888/testar and

http://localhost:8888/testar/?replytocom=9#respond

是的,你忘了打电话给comment_form();

所以你的代码在注释中。php应该如下所示

<?php if ( get_comment_pages_count() > 1 && get_option( \'page_comments\' ) ) : // are there comments to navigate through ?>
    <nav id="comment-nav-above" class="comment-navigation" role="navigation">
        <h1 class="screen-reader-text"><?php _e( \'Comment navigation\', \'triday\' ); ?></h1>
        <div class="nav-previous"><?php previous_comments_link( __( \'← Older Comments\', \'triday\' ) ); ?></div>
        <div class="nav-next"><?php next_comments_link( __( \'Newer Comments →\', \'triday\' ) ); ?></div>
    </nav><!-- #comment-nav-above -->
    <?php endif; // check for comment navigation ?>

    <ol class="comment-list">
        <?php
            /* Loop through and list the comments. Tell wp_list_comments()
             * to use triday_comment() to format the comments.
             * If you want to override this in a child theme, then you can
             * define triday_comment() and that will be used instead.
             * See triday_comment() in inc/template-tags.php for more.
             */
             wp_list_comments( array( \'callback\' => \'triday_comment\' ) );
            ?>

    </ol><!-- .comment-list -->

    <?php if ( get_comment_pages_count() > 1 && get_option( \'page_comments\' ) ) : // are there comments to navigate through ?>
    <nav id="comment-nav-below" class="comment-navigation" role="navigation">
        <h1 class="screen-reader-text"><?php _e( \'Comment navigation\', \'triday\' ); ?></h1>
        <div class="nav-previous"><?php previous_comments_link( __( \'← Older Comments\', \'triday\' ) ); ?></div>
        <div class="nav-next"><?php next_comments_link( __( \'Newer Comments →\', \'triday\' ) ); ?></div>
    </nav><!-- #comment-nav-below -->
    <?php endif; // check for comment navigation ?>

<!--</div>-->
<?php comment_form(); ?>

结束

相关推荐

Disable comments

我想知道是否有任何方法可以阻止用户留下评论,但仍然显示评论表单?因此,无论何时发布新评论,都应该自动将其丢弃,或者根本不应该添加。我的评论表单仅用于演示目的,它不应该接受任何评论,但应该显示出来。我已经找到了preprocess_comment 和comment_post hooks,但我不知道如何利用它来阻止评论。我在想这样的事情:function prefix_delete_comments( $comment_id ) { wp_delete_comment( $comment_id,