首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >comment_reply_link未显示

comment_reply_link未显示
EN

Stack Overflow用户
提问于 2013-08-31 18:20:16
回答 1查看 4.2K关注 0票数 1

我想为评论创建自己的模板,所以我运行了foreach,结果如下:

代码语言:javascript
复制
<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中找到的解决方案,但它对我不起作用。

代码语言:javascript
复制
comment_reply_link( array('reply_text' => 'Reply this comment'), comment_ID(), the_ID() );

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

我能做什么?

EN

回答 1

Stack Overflow用户

发布于 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语句:

代码语言:javascript
复制
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中执行以下操作:

代码语言:javascript
复制
$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); 

然后链接就会显示出来。

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18547040

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档