實(shí)現(xiàn)WordPress顯示當(dāng)前作者相關(guān)日志的方法
來源:程序員人生 發(fā)布時(shí)間:2014-03-08 22:08:03 閱讀次數(shù):2776次
實(shí)現(xiàn)WordPress顯示當(dāng)前作者相關(guān)日志的方法,本文來源:wordpress.la
顯示相關(guān)文章可以吸引訪客進(jìn)一步閱讀你的網(wǎng)站,今天分享的這一段代碼就是顯示訪客當(dāng)前閱讀的文章作者的另外五篇文章。
同樣是把第一段代碼放在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(); ?>