将代码加到侧边栏 sidebar.php 模板中,当打开文章作者所有文章归档页面,会显示 10 篇该作者最近发表过评论的文章。
- <?php if ( is_author() ) { ?>
- <?php
- $author_email = get_the_author_meta( 'user_email' );
- $args = array(
- 'author_email' => $author_email,
- 'number' => '10'
- );
- $comments = get_comments($args);
- foreach($comments as $comment) :
- 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/;
- endforeach;
- ?>
- <?php } ?>
当然如果想让上述代码能适配主题样式结构,还需要加上适当的 DIV,比如适配 WordPress 默认主题 Twenty Sixteen,代码应该是这样:
- <?php if ( is_author() ) { ?>
- <aside id="secondary" class="sidebar widget-area" role="complementary">
- <section id="user-p" class="widget widget_categories">
- <h2 class="widget-title">评论过的文章</h2>
- <ul class="user-p-widget">
- <?php
- $author_email = get_the_author_meta( 'user_email' );
- $args = array(
- 'author_email' => $author_email,
- 'number' => '10'
- );
- $comments = get_comments($args);
- foreach($comments as $comment) :
- 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/;
- endforeach;
- ?>
- </ul>
- </section>
- </aside>
- <?php } ?>
其它主题需要查看主题侧边栏小工具结构,修改其中的结构代码。
- 1、本站大部分内容均收集于网络,若内容侵犯到您的权益,请发送邮件至:service@wuyanshuo.cn,我们将第一时间处理!
- 2、本站资源所需价格并非资源售卖价格,是收集、整理、编辑以及本站运营的适当补贴,并且本站不提供任何免费技术服务。
- 3、所有资源仅限参考和学习,版权归原作者所有,更多请阅读无言说网络服务器协议。