本文整理自网络,侵删。
因为用户寻找的是相关的文章,不相关的文章是没有多大兴趣看,博客吧认为这样也能提高PVwordpress显示当前文章同分类最新文章列表:
在想要显示的地方添加以下代码:
代码如下:
<?php
/*
single page?show current category articles
*/
?>
<?php
if ( is_single() ) :
global $post;
$categories = get_the_category();
foreach ($categories as $category) :
?>
<li class="widget widget_recent_entries" id="<?php $category->term_id;?>-posts">
<h2 class="widgettitle"><?php echo $category->name; ?></h2>
<ul>
<?php
$posts = get_posts('numberposts=5&category='. $category->term_id);
foreach($posts as $post) :
?>
<li>
<a ><?php the_title(); ?></a>
</li>
<?php endforeach; ?>
</ul>
</li>
<?php
endforeach; endif ; ?>
<?php
/*
end show current category articles
*/
?>
以上代码是显示当前文章页面显示该文章所在的分类的最新文章:如果是显示在侧栏,则在sidebar.php文件里添加,如果是显示在文章下面,请在single.php文件里添加。
<?php
/*
single page?show current category articles
*/
?>
<?php
if ( is_single() ) :
global $post;
$categories = get_the_category();
foreach ($categories as $category) :
?>
<li class="widget widget_recent_entries" id="<?php $category->term_id;?>-posts">
<h2 class="widgettitle"><?php echo $category->name; ?></h2>
<ul>
<?php
$posts = get_posts('numberposts=5&category='. $category->term_id);
foreach($posts as $post) :
?>
<li>
<a ><?php the_title(); ?></a>
</li>
<?php endforeach; ?>
</ul>
</li>
<?php
endforeach; endif ; ?>
<?php
/*
end show current category articles
*/
?>
以上代码是显示当前文章页面显示该文章所在的分类的最新文章:如果是显示在侧栏,则在sidebar.php文件里添加,如果是显示在文章下面,请在single.php文件里添加。
标签:WordPress
相关阅读 >>
利用fix rss feeds插件修复wordpress的feed显示错误
wordpress使用rss feed输出自定义文章类型内容的方法
更多相关阅读请进入《wordpress》频道 >>
相关推荐
评论
管理员已关闭评论功能...
- 欢迎访问木庄网络博客
- 可复制:代码框内的文字。
- 方法:Ctrl+C。