当前位置:首页文章笔记建站教程WordPress 显示文章作者最近发表过评论的文章

WordPress 显示文章作者最近发表过评论的文章

将代码加到侧边栏 sidebar.php 模板中,当打开文章作者所有文章归档页面,会显示 10 篇该作者最近发表过评论的文章。

  1. <?php if ( is_author() ) { ?>
  2. <?php
  3. $author_email = get_the_author_meta( ‘user_email’ );
  4. $args = array(
  5. ‘author_email’ => $author_email,
  6. ‘number’ => ’10’
  7. );
  8. $comments = get_comments($args);
  9. foreach($comments as $comment) :
  10. echo(‘<li class="comment">’ . $somment->comment_content),‘<h5><a href=’https://www.22vd.com/.get_permalink($comment->comment_post_ID).‘>’https://www.22vd.com/, get_the_title($comment->comment_post_ID), ‘</a></h5>’https://www.22vd.com/, ‘<time><em>’ . $comment->get_comment_date . ‘</em></time>’https://www.22vd.com/, ‘</li>’https://www.22vd.com/;
  11. endforeach;
  12. ?>
  13. <?php } ?>

当然如果想让上述代码能适配主题样式结构,还需要加上适当的 DIV,比如适配 WordPress 默认主题 Twenty Sixteen,代码应该是这样:

  1. <?php if ( is_author() ) { ?>
  2. <aside id="secondary" class="sidebar widget-area" role="complementary">
  3. <section id="user-p" class="widget widget_categories">
  4. <h2 class="widget-title">评论过的文章</h2>
  5. <ul class="user-p-widget">
  6. <?php
  7. $author_email = get_the_author_meta( ‘user_email’ );
  8. $args = array(
  9. ‘author_email’ => $author_email,
  10. ‘number’ => ’10’
  11. );
  12. $comments = get_comments($args);
  13. foreach($comments as $comment) :
  14. echo(‘<li class="comment">’ . $somment->comment_content),‘<a href=’https://www.22vd.com/.get_permalink($comment->comment_post_ID).‘>’https://www.22vd.com/, get_the_title($comment->comment_post_ID), ‘</a>’https://www.22vd.com/, ‘<time><em>’ . $comment->get_comment_date . ‘</em></time>’https://www.22vd.com/, ‘</li>’https://www.22vd.com/;
  15. endforeach;
  16. ?>
  17. </ul>
  18. </section>
  19. </aside>
  20. <?php } ?>

其它主题需要查看主题侧边栏小工具结构,修改其中的结构代码。

温馨提示:

文章标题:WordPress 显示文章作者最近发表过评论的文章

文章链接:https://www.wuyanshuo.cn/763.html

更新时间:2022年04月21日

本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:service@wuyanshuo.cn我们将第一时间处理! 资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。 所有资源仅限于参考和学习,版权归原作者所有,更多请阅读无言说网络服务协议

给TA打赏
共{{data.count}}人
人已打赏
建站教程

更改WordPress编辑器中“在此输入标题”占位符提示文字

2022-4-21 11:00:48

建站教程

WordPress后台直接显示文章、页面、分类、标签和用户等ID号

2022-4-21 14:02:56

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索
'