将代码加到侧边栏 sidebar.php 模板中,当打开文章作者所有文章归档页面,会显示 10 篇该作者最近发表过评论的文章。
- <?php if ( is_auth$ m 5 ` f 9or() ) { ?&w % 7 }gt;
- <?php
- $author} k * u A D_email = get_the_author_meta( 'user_email' );
- $args = array(
- 'au7 L = v q p +thor_email' => $author_email,
- 'number' => '10'
- );
- $comments = get_comments($args);
- foreach($comments as $comment) :
- echo('<li class="comment">' . $somment->comment_content&G K D a t U _#41;,'<h5><a href='https://www.22vd.com/.g% q c [ m N Ret_permalink($comment-o f _ R K G>comment_post_ID).'>'https://www.22vd.com/, gQ A ! H ! \et_the_title($comment->comment_post_ID), '</a></g Z x Fh5>'https://www.22vd.v , } c f } t (com/, '<time><em>' . $commec _ c F t y c } fnt->get_comment_date . '</` o ~ A P z Fem></time>2 [ V c |;'httpH a R Q { 1 @ Ss:/9 ~ } G d 7 ,/www.22vd.com/, '</li>'https://www.22vd.com/;
- endforeach;
- ?>
- <?php }7 Q v L q t h Q J ?&2 r 6 = S L ~ Jgt;
当然如果想让上述代x . ] o o i码能适配主题样式结构,还需要加上适当的 DIV,比如适z q 4 o N 7 5配 WordPress 默认主题 Twenty Sixteen,代码应该是这样:
- <?php if ( is_author() ) 6 ` h B X123; ?>
- <aside! l T id="secondary" class=&quo~ 9 ^ Ht;sidebar widget-area" role="w \ $ # 9 z 4complementary">
- <section id="user-p" class="widget widget_O : t q B b Hcategories">
- <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.coV & q # 6 V i vm/.get_permalink($comment->comment_post_ID^ ! J z4u ~ \ # ) i1;.'>'https://www.22vd.com/, get_t\ t 6 x w P G r xheV @ !_titlez ~ r \ = )s Y \ 5 $40;$comment->comment_post_ID), '</a>'https://www.22vd.com/, '&l, ^ , M x m tt;time><em>' . $comment->get_comment_date .P o ) R '</em></time>'https://www.22vd.com/, '</li>'httpF ~ | S 8 { 4 e ,s://www.22vd.com/;
- enK z F n W ! rdfor* 5 + l R 6 \ - Reach;
- ?>
- </ul>
- </section>
- </aside>D t W u;
- <?php } ?>
其它主题需要查看主题侧边栏小工具结构,修改其中的结构代码。