为 wordpress 文章作者在评论留言时显示“本文作者”提示
- 时间:2020-05-17 12:16:18
- 分类:网络文摘
- 阅读:135 次
如果你的 wordpress 博客有很多作者,那么当作者在自己的文章中回复读者评论留言时,在名称后面显示“本文作者”提示,可以让读者明确知道是作者亲自回复自己的留言,这对促进作者与读者之间的互动会很有帮助。当然,对于单一作者的博客,还是用网上盛传的“管理员“提示更好些。

首先将下面判断文章作者代码添加到当前 wordpress主题函数模板 functions.php 中:
- / 判断文章作者
- function zm_comment_by_post_author( $comment = null ) {
- if ( is_object( $comment ) && $comment->user_id > 0 ) {
- $user = get_userdata( $comment->user_id );
- $post = get_post( $comment->comment_post_ID );
- if ( ! emptyempty( $user ) && ! emptyempty( $post ) ) {
- return $comment->user_id === $post->post_author;
- }
- }
- return false;
- }
将显示调用代码添加到主题评论模板显示评论者名称代码的后面即可。
- <?php
- $post_author = zm_comment_by_post_author( $comment );
- if ( $post_author ) {
- echo '<span class="post-author">文章作者</span>';
- }
- ?>
不同主题评论模板代码不同,具体加到哪个位置,只能自行研究了。
同时显示管理员和作者的调用方法:
- <?php
- if ($comment->comment_author_email == get_option('admin_email')) {
- echo '<span class="author-admin">博主</span>';
- } else {
- $post_author = zm_comment_by_post_author( $comment );
- if ( $post_author ) {
- echo '<span class="post-author">作者</span>';
- }
- }
- ?>
判断作者代码取自WordPress默认主题Twenty Twenty,默认主题虽然外观看似简单,但功能真的很强大,有很多东西值得挖掘。
原文:https://zmingcx.com/wordpress-comment-is-article-author.html
推荐阅读:Why Aren’t Your Visitors Sharing Your Post on Social Media Bloggers: Jumpstart Cash Flow With These Tips 4 Tips to Accelerate Your Business Blog The Epidemic Of Hate Continues In Great Britain As Conservative Russian Blogger Arrested for “Inciting Hatred” by Playing Pokemo 4Sum – Find Unique Quadruplets that Sum to Target using O( The Subsequence Algorithm for Two Strings – How to Check i Using Greedy Algorithm to Fix the Broken Calculator Beginner’s Guide to the zip() function in Python3 Passengers Pick-up and Drop-off Algorithms (Car Pooling) via Gre
- 评论列表
-
- 添加评论