您的位置:首页 > 教程笔记 > 综合教程

WordPress怎么同时调用多个分类下的文章

2020-10-10 21:17:59 综合教程 27

WordPress调用指定某个分类下的文章的代码是:

<? if (have_posts()) : ?><? query_posts('cat=ID号' . $mcatID. '&caller_get_posts=1&showposts=显示数量'); ?><? while (have_posts()) : the_post(); ?><a href="<? the_permalink() ?>" target="_blank"><? the_title(); ?></a><? endwhile;?><? endif; wp_reset_query(); ?>

那么有时需要在某个区域调用网站里多个分类下的文章,这该怎么办呢?看下面代码

<?            $args=array(                'cat' => array(16,17,18,19,20),   // 分类ID                'posts_per_page' => 32, // 显示篇数            );            query_posts($args);            if(have_posts()) : while (have_posts()) : the_post();            ?><a href="<? the_permalink() ?>" target="_blank"><? the_title(); ?></a>            </li>                   <?  endwhile; endif; wp_reset_query(); ?>

代码说明:

cat:设置调用哪些分类下的文章,写分类目录ID号;

posts_per_page:设置调用显示文章数量;

相关推荐