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

将代码加到侧边栏sidebar.php模板中,当打开文章作者所有文章归档页面,会显示10篇该作者最近发表过评论的文章。 <?php if ( is_author() ) { ?> <?php $author_email = get_the_author_meta( 'user_email' ); $a...
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 } ?>

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

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

在WordPress分类目录小工具中显示空的分类

2023-2-16 23:47:42

wordpress教程

一句代码禁用Gutenberg(古腾堡) 编辑器

2023-2-16 23:47:42

【腾讯云】11.11云上盛惠!云服务器首年1.8折起,买1年送3个月!
11.11云上盛惠!海量产品·轻松上云!云服务器首年1.8折起,买1年送3个月!超值优惠,性能稳定,让您的云端之旅更加畅享。
查看更多相关信息>>
站长

(工作日 10:00 - 22:30 为您服务)

2026-03-26 05:12:15

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

猜你想问:

  • 购买的模板免费包安装吗?

  • 这个演示地址有吗?

  • 购买vip会员可以下载哪些模板?

您的留言我们已经收到,我们将会尽快跟您联系!
取消
立即选择任一渠道联系我们