Outputting Articles from a Specific Category Directory in WordPress

Publish: 2016-12-05 | Modify: 2017-06-21

Sometimes we need to output the articles of a specific column in WordPress to a specified location. It's actually very simple, just a piece of code can do it.

wordpress-bg-medblue

Get the category ID

In the WordPress backend -> Posts -> Categories, find the category you need and click to open it. For example, open the SEO column link from the backend of Xiaoz Blog. You will see that the link address contains tag_ID=745, where 745 is the ID of the SEO column. We need to record it for later use.

2016-12-03_144646

Add code

Add the following code to the page where you want to display the articles. Adjust the category ID and the number of articles to display according to your actual needs.

<ul>  
<?php  
    $args=array(  
        'cat' => 745,   // Category ID  
        'posts_per_page' => 10, // Number of articles to display  
    );  
    query_posts($args);  
    if(have_posts()) : while (have_posts()) : the_post();  
?>  
    <li>  
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    </li>  
<?php  endwhile; endif; wp_reset_query(); ?>  
</ul> 

Comments