获取指定分类文章虽说是一个很简单的功能,但也是我们在开发WordPress主题中很常见的需求,那么如何才能获取到指定分类的文章的文章呢?
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代码复制粘贴到主题需要调用指定分类文章的文件里即可。

更多技术教程,请关注技术教程网www.jishujc.com