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中的rel=”noopener”是什么?

2023-2-16 23:47:40

wordpress教程

修改WordPress密码保护文章留言信息提示文字

2023-2-16 23:47:43

!
你也想出现在这里?立即 联系我们吧!
信息
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
搜索