# 输出指定分类目录文章列表
> WordPress首页或其它页面需要调取指定分类目录文章列表时,可以使用以下方法:
> 通过while循环语句,设定指定栏目ID、调取数目等参数,从而遍历出所需的数据
> 数据包括:文章链接、标题、摘要、内容、特色图像、发布日期(年月日)等
```
<ul class="list-none">
<?php
$news1_query = new WP_Query( array( 'cat' => 1, 'posts_per_page' => 4 ) ); //栏目ID,调取数目
if ( $news1_query ->have_posts() ):
while ( $news1_query ->have_posts() ) : $news1_query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
<?php the_ID(); ?>
<?php the_title(); ?>
<?php the_permalink(); ?>
<?php the_time('Y-n-d'); ?>
<?php the_time('d'); ?>
<?php the_time('Y-n'); ?>
<?php echo get_the_excerpt(); ?>
<?php the_author(); ?>
<?php the_category(', ') ?>
<?php if ( has_post_thumbnail() ):
the_post_thumbnail('index_news_size'); ?>
<?php else: ?>
<img src="<?php bloginfo('template_url'); ?>/assets/img/thumbnail.jpg" alt="<?php the_title(); ?>">
<?php endif; ?>
规格:<?php echo get_post_meta($post->ID, '规格', true); ?>
</li>
<?php endwhile;
endif;
wp_reset_postdata(); ?>
</ul>
```