主页 > 编程资料 > WordPress >
发布时间:2015-09-26 作者:网络 阅读:192次
因为用户寻找的是相关的文章,不相关的文章是没有多大兴趣看,博客吧认为这样也能提高PV
wordpress显示当前文章同分类最新文章列表:

在想要显示的地方添加以下代码:

复制代码代码如下:
/*
single page?show current category articles
*/
?>
if ( is_single() ) :
global $post;
$categories = get_the_category();
foreach ($categories as $category) :
?>

  • name; ?>



      $posts = get_posts('numberposts=5&category='. $category->term_id);
      foreach($posts as $post) :
      ?>






  • endforeach; endif ; ?>
    /*
    end show current category articles
    */
    ?>

    以上代码是显示当前文章页面显示该文章所在的分类的最新文章:如果是显示在侧栏,则在sidebar.php文件里添加,如果是显示在文章下面,请在single.php文件里添加。
    关键字词: