WordPress 显示文章作者最近发表过评论的文章
wordpress 显示文章作者最近发表过评论的文章” />
将代码加到侧边栏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=’.get_permalink($comment->comment_post_ID).’>’, get_the_title($comment->comment_post_ID), ‘</a></h5>’, ‘<time><em>’ . $comment->get_comment_date . ‘</em></time>’, ‘</li>’;
- 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=’.get_permalink($comment->comment_post_ID).’>’, get_the_title($comment->comment_post_ID), ‘</a>’, ‘<time><em>’ . $comment->get_comment_date . ‘</em></time>’, ‘</li>’;
- endforeach;
- ?>
- </ul>
- </section>
- </aside>
- <?php } ?>
其它主题需要查看主题侧边栏小工具结构,修改其中的结构代码。
大熊wordpress凭借多年的wordpress企业主题制作经验,坚持以“为用户而生的wordpress主题”为宗旨,累计为2000多家客户提供品质wordpress建站服务,得到了客户的一致好评。我们一直用心对待每一个客户,我们坚信:“善待客户,将会成为终身客户”。大熊wordpress能坚持多年,是因为我们一直诚信。我们明码标价(wordpress做网站需要多少钱),从不忽悠任何客户,我们的报价宗旨:“拒绝暴利,只保留合理的利润”。如果您有网站建设、网站改版、网站维护等方面的需求,请立即咨询右侧在线客服或拨打咨询热线:18324743309,我们会详细为你一一解答你心中的疑难。
写给所有做网站的朋友的一封信
现在就开始执行“1+N”互联网推广和没有开始执行的人,一两天看不出任何区别; 一两个月看来差异也是微乎其微的;但在2-5年的长远时间来看的时候,你的高质量询盘不断增加,你的互联网资产已经建立完成,对手已经很难匹敌,现在你看到这段文字的时候就是最好的开始,现在就是最好的时候,马上开始“1+N”体系的整体互联网推广吧,我们和你一起,开创互联网大未来!