Wordpress是很强大的网站内容管理系统,你可以通过相关函数就能实现相关的功能。会代码相关的人都会上手自己修改主题,那么很多人都不知道Wordpress调用指定分类文章代码是哪些,今天就为大家分享
<ul>
<?php query_posts('cat=1&showposts=5'); //cat是要调用的分类ID,showposts是需要显示的文章数量 ?>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; wp_reset_query(); ?>
</ul>Wordpress在首页列出所有分类及分类下的文章
前面我们谈了wordpress调用指定分类文章,如果想要调用所有分类的文章如何实现呢?比如在wordpress首页列出所有分类及分类下的文章,其实方法类似
<?php
$cats = get_categories();
foreach ( $cats as $cat ) {
query_posts( 'showposts=10&cat=' . $cat->cat_ID );
?>
<h3><?php echo $cat->cat_name; ?></h3>
<ul class="sitemap-list">
<?php while ( have_posts() ) { the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php } wp_reset_query(); ?>
</ul>
<?php } ?>
