wordpress自定义评论表单字段调用函数get_comment_meta()
前面博客吧分享了wordpress增加文章评论表单字段的教程,通过该教程可以给wordpress文章的评论表单增加如QQ、微博、电话等各种需要的表单字段,用户提交的信息可以在后台评论里查看。但是如果想把信息显示在前台用户的评论里要怎么做?方法是使用get_comment_meta()
函数调用。
函数结构:
1 | <?php get_comment_meta( $comment_id, $key, $single ); ?> |
参数说明:
- $comment_id – 评论的id,当前评论使用
$comment->comment_ID
获取。 - $key – 字段名。
- $single – 布尔型,true或false,设置为true返回一个字符串,设置为false,返回一个数组。
示例:
通过该函数调用wordpress增加文章评论表单字段教程里增加的QQ字段。在当前主题的comments.php文件wp_list_comments()
函数的回调函数里添加以下代码:
1 2 3 4 5 | <?php if(get_comment_meta($comment->comment_ID,'qq',true)){ echo get_comment_meta($comment->comment_ID,'qq',true); } ?> |
除非注明,文章均由 博客吧 整理发布,欢迎转载。
转载请注明本文地址:https://www.boke8.net/wordpress-get_comment_meta.html
如果喜欢,可以:点此订阅本站
发表留言