我想为评论创建自己的模板,所以我运行了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>一切都好,但我不能让comment_reply_link工作。我尝试使用在Wordpress Comment reply link does not appear中找到的解决方案,但它对我不起作用。
comment_reply_link( array('reply_text' => 'Reply this comment'), comment_ID(), the_ID() );给我一些数字(可能是评论的时间戳)。
我能做什么?
发布于 2013-12-30 08:43:57
如果您使用的不是wp_list_comments,而是get_comments,然后像上面那样运行for each,那么comment_reply_link的问题如下:
在wordpress comment-template.php中,comment_reply_link使用的get_comment_reply_link在$args['max_depth']中有一个NULL值,因此使用下面的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;始终为真,并且函数过早退出。即使您设置了'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); 然后链接就会显示出来。
https://stackoverflow.com/questions/18547040
复制相似问题