【问题标题】:Custom wordpress comments css class自定义wordpress评论css类
【发布时间】:2012-12-17 07:04:01
【问题描述】:

有没有办法向 cmets 添加一个自定义类,它是父评论的“回复评论”?

*注意:我的模板使用'max_depth' => '1'。

输出代码:

<div>
  <div class="comment-1"></div> // comment 1
    <div class="comment-2"></div> // reply 1
    <div class="comment-3"></a functiondiv> // reply 2
  <div class="comment-4"> // comment 2
</div>

我需要一个回复类,例如:

<div>
  <div class="comment-1"></div> // comment 1
    <div class="comment-2" class="reply"></div> // reply 1
    <div class="comment-3" class="reply"></div> // reply 2
  <div class="comment-4"> // comment 2
</div>

过滤器还是函数?

编辑:
循环 cmets 的代码是:

  1. comments.php
    wp_list_cmets(array('style' => 'div', 'type' => 'comment', 'max_depth' => '1' , 'callback' => 'cmets_template'));

  2. functions.php
    http://pastebin.com/4T5DiZY4

【问题讨论】:

  • 你能给出循环cmets的代码吗?
  • 我刚刚编辑了主帖。请检查一下。如果您能帮助我,我将不胜感激。

标签: wordpress class function filter


【解决方案1】:

函数comment_class()有一个同名过滤器comment_class

function parent_comment_SE_14130085($classes, $class, $comment_id, $post_id) {
    $cur_comment = get_comment($comment_id);

    if ( ! empty( $cur_comment->comment_parent ) ) {
        $classes[] = 'nested';
    }
    return $classes;
}
add_filter('comment_class', 'parent_comment_SE_14130085', 10, 4);

【讨论】:

  • 我已将此代码放在functions.php 中,但在每条评论中都出现了一些“缺少参数”错误 - “for parent_comment_SE_14130085()”。
  • 好的,我刚刚修复了这个错误。现在完美运行,正是我需要的 :) 感谢您的宝贵时间。
  • 哦,是的,我忘记了 add_filter 的参数更新了我的答案
猜你喜欢
  • 2013-07-27
  • 2012-02-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-27
  • 2011-11-29
  • 1970-01-01
  • 2013-01-14
相关资源
最近更新 更多