你想在WordPress中显示相同作者的相关文章吗? 通常,您可以使用任何相关的文章插件在您的网站上显示类似的文章。 但是,如果您的WordPress网站有多个作者,则用户可能需要阅读同一作者的其他内容。 在本文中,我们将向您展示如何在WordPress中显示相同作者的相关文章。
此方法要求您将代码添加到WordPress主题文件中。 您需要将以下代码添加到主题的functions.php文件或特定于站点的插件中。
function ie_related_author_posts($content) {
 
if ( is_single() ) { 
    global $authordata, $post;
     
    $content .= '<h4>Similar Posts by The Author:</h4> ';
  
    $authors_posts = get_posts( array( 'author' => $authordata->ID, 'post__not_in' => array( $post->ID ), 'posts_per_page' => 5 ) );
  
    $content .= '<ul>';
    foreach ( $authors_posts as $authors_post ) {
        $content .= '<li><a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a></li>';
    }
    $content .= '</ul>';
  
    return $content;
    } 
    else { 
    return $content; 
    }
}
 
add_filter('the_content','ie_related_author_posts'); - 提示:这篇文章发布于 2018/06/07,作者 99839,总计 756 字.
- 原文: 教程:如何显示相同的作者在WordPress的相关文章 | 爱壹主题








 
  
  
  
  
 
 
 














