# 輸出指定分類目錄文章列表
> 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>
```