获取指定分类文章虽说是一个很简单的功能,但也是我们在开发WordPress主题中很常见的需求,那么如何才能获取到指定分类的文章的文章呢?
很简单,几行代码就能够搞定。
<ul> <?php $args=array( \'cat\' => 1, // 分类ID \'posts_per_page\' => 10, // 显示文章篇数 ); query_posts($args); if(have_posts()) : while (have_posts()) : the_post(); ?> <li> <a href=\"<?php the_permalink(); ?>\" rel=\"external nofollow\" ><?php the_title(); ?></a> </li> <?php endwhile; endif; wp_reset_query(); ?>
将以上面WordPress代码复制粘贴到主题需要调用指定分类文章的文件里即可。
标签:
本文链接:https://www.xiaba.cc/html/2085.html
版权声明:站内所有文章皆来自网络转载,只供模板演示使用,并无任何其它意义!