欢迎您光临自学哈网,只为分享网络知识教程,供大家学习参考!

「自学哈网」WordPress 显示文章作者最近发表过评论的文章

作者 : 自学哈 本文共1237个字,预计阅读时间需要4分钟 2022-11-6 共141人阅读
也想出现在这里? 联系我们

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 } ?>

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

本站声明:
本站所有资源来源于网络,分享目的仅供大家学习和交流!如若本站内容侵犯了原著者的合法权益,可联系邮箱976157886@qq.com进行删除。
自学哈专注于免费提供最新的分享知识、网络教程、网络技术的资源分享平台,好资源不私藏,大家一起分享!

自学哈网 » 「自学哈网」WordPress 显示文章作者最近发表过评论的文章
也想出现在这里? 联系我们
© 2022 Theme by - 自学哈网 & WordPress Theme. All rights reserved 浙ICP备2022016594号