wordpress侧边栏,当前文章页所在分类栏目下的文章列表
<?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); //5为循环条数
foreach($posts as $post) :
?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach; ?>
</ul>
</li>
<?php
endforeach; endif ;
?>
希望以上内容对你有所帮助!如果还有其他问题,请随时提问。 各类知识收集 拥有多年CMS企业建站经验,对 iCMS, LeCMS, ClassCMS, Fastadmin, PbootCMS, PHPCMS, 易优CMS, YzmCMS, 讯睿CMS, 极致CMS, Wordpress, HkCMS, YznCMS, WellCMS, ThinkCMF, 等各类cms的相互转化,程序开发,网站制作,bug修复,程序杀毒,插件定制都可以提供最佳解决方案。