comment_reply_link没有显示

Tom*_*ski 0 wordpress

我想创建自己的评论模板,所以我确实运行了foreach,结果出来了:

<dl class="commentlist">
    <?php foreach ($comments as $comment) : ?>
        <dt><?php printf(__('%s'), get_comment_author_link()) ?> <em><?php echo human_time_diff( get_comment_time('U'), current_time('timestamp') ); ?> <?php echo get_locale() == 'pl_PL' ? 'temu' : 'ago'; ?></em></dt>
        <dd>
            <?php if ($comment->comment_approved == '0') : ?>
                <em>Komentarz czeka na zatwierdzenie</em><br />
            <?php endif; ?>

            <?php comment_text(); ?>
            <?php comment_reply_link( array ( 'reply_text' => 'Reply this comment' ) ); ?>
        </dd>
    <?php endforeach; ?>
</dl>
Run Code Online (Sandbox Code Playgroud)

一切都好,但我无法comment_reply_link上班.我尝试使用Wordpress中找到的解决方案评论回复链接没有出现,但它对我不起作用.

comment_reply_link( array('reply_text' => 'Reply this comment'), comment_ID(), the_ID() );
Run Code Online (Sandbox Code Playgroud)

给了我一些数字(可能是评论的时间戳).

我能做什么?

小智 6

如果您正在使用不使用wp_list_comments但是例如get_comments然后为每个运行一个,如上所述,问题comment_reply_link是如下:

在wordpress comment-template.php中,get_comment_reply_linkused by comment_reply_link有一个NULL值,$args['max_depth']因此下面的if语句:

function get_comment_reply_link($args = array(), $comment = null, $post = null) {

$defaults = array(
    'add_below'  => 'comment',
    'respond_id' => 'respond',
    'reply_text' => __('Reply'),
    'login_text' => __('Log in to Reply'),
    'depth'      => 0,
    'before'     => '',
    'after'      => ''
);

$args = wp_parse_args($args, $defaults);

if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] )
    return;
Run Code Online (Sandbox Code Playgroud)

永远是真的,功能不成熟.即使你设定'depth' => 1.因为NULL总是小于0,1等等.您无法编写自定义过滤器,comment_reply_link因为稍后在函数中调用该钩子.

我在没有更改comment-template.php文件的情况下找到的唯一方法是在我的comment.php中执行以下操作:

$post_id = get_the_ID();
$comment_id =get_comment_ID();

//get the setting configured in the admin panel under settings discussions "Enable threaded (nested) comments  levels deep"  
$max_depth = get_option('thread_comments_depth');
//add max_depth to the array and give it the value from above and set the depth to 1
$default = array(
    'add_below'  => 'comment',
    'respond_id' => 'respond',
    'reply_text' => __('Reply'),
    'login_text' => __('Log in to Reply'),
    'depth'      => 1,
    'before'     => '',
    'after'      => '',
    'max_depth'  => $max_depth
    );
                    comment_reply_link($default,$comment_id,$post_id); 
Run Code Online (Sandbox Code Playgroud)

然后链接将显示出来.