加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > CMS系统 > wordpress > 正文

实现WordPress显示当前作者相关日志的方法

发布时间:2020-12-14 14:20:13 所属栏目:wordpress 来源:网络整理
导读:实现WordPress显示当前作者相关日志的方法,本文来源:wordpress.la 显示相关文章可以吸引访客进一步阅读你的网站,今天分享的这一段代码就是显示访客当前阅读的文章作者的另外五篇文章。 同样是把第一段代码放在functions.php中。 function get_related_aut

实现WordPress显示当前作者相关日志的方法,本文来源:wordpress.la

显示相关文章可以吸引访客进一步阅读你的网站,今天分享的这一段代码就是显示访客当前阅读的文章作者的另外五篇文章。
同样是把第一段代码放在functions.php中。

function get_related_author_posts() {
global $authordata,$post;
$authors_posts = get_posts( array( 'author' => $authordata->ID,'post__not_in' => array( $post->ID ),'posts_per_page' => 5 ) );
$output = '<ul>';
foreach ( $authors_posts as $authors_post ) {
$output .= '<li><a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title',$authors_post->post_title,$authors_post->ID ) . '</a></li>';
}
$output .= '</ul>';
return $output;
}

然后把第二段代码放在single.php中你想显示的地方。

<?php echo get_related_author_posts(); ?>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读