自定义评论标记

在典型的WordPress主题中,您可以使用wp_list_comments()函数输出帖子/页面的注释的完整列表。 通过自定义为该注释列表生成HTML标记的方式,此功能提供的功能不多。 要为注释列表编写自己的标记,可以在wp_list_comments()中使用回调函数作为参数,因此它也非常抽象。

在functions.php中

<?php
function my_custom_comments($comment, $args, $depth) {
   $GLOBALS['comment'] = $comment; ?>
   <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
   <?php if ($comment->comment_approved == '0') : ?>
      <em><?php _e('Your comment is awaiting moderation.') ?></em>
   <?php endif; ?>

   // Comments markup code here, e.g. functions like comment_text(); 

}
?>

在comments.php中

<?php 
   wp_list_comments("callback=my_custom_comments"); 
?>

翻译自: https://css-tricks.com/snippets/wordpress/customize-comments-markup/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值