阿里云服务器

wordpress模板制作,修改的时候常常需要调用不同分类里的文章。下面我给大家介绍一个方法:

按分类显示每个分类的最新文章,代码如下:(其中的1,3,4,5,6,7是你要显示的分类ID号)

XML/HTML代码
  1. <?php $display_categories = array(1,3,4,5,6,7); foreach ($display_categories as $category) { ?>  

  2. <div class="postlist">  

  3. <?php query_posts("showposts=5&cat=$category"); $wp_query->is_category = false; $wp_query->is_archive = false; $wp_query->is_home = true?>  

  4. <h3 class="posttitle"><span class="more"><a href="<?php echo get_category_link($category);?>">&raquo; 查看更多</a></span><?php single_cat_title(); ?></h3>  

  5. <ul>  

  6. <?php if (have_posts()) : ?>  

  7. <?php while (have_posts()) : the_post(); ?>  

  8. <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>  

  9. <?php endwhile; ?>  

  10. <?php else : ?><p class="center">此分类暂无内容</p>  

  11. <?php endif; ?>  

  12. </ul>  

  13. </div>  

  14. <?php } ?>  


显示指定分类的描述(1代表分类ID为1)

XML/HTML代码
  1. <?php echo category_description(1); ?>  


相关阅读: