Title: get_posts &#8212; show category title?
Last modified: August 22, 2016

---

# get_posts — show category title?

 *  [intricateartist](https://wordpress.org/support/users/intricateartist/)
 * (@intricateartist)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/get_posts-show-category-title/)
 * How do I display the category title at the top of the list of posts retrieved
   from the category? I’m not having any luck finding a solution.
 * My code:
 *     ```
       <?php $args = array( 'posts_per_page' => 3, 'category' => 1 );
       $myposts = get_posts( $args );
       foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
   
       <!--WANT CATEGORY TITLE DISPLAYED HERE-->
   
       <li>
       	<?php if ( has_post_thumbnail() ) : ?>
       	<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
       	<?php the_post_thumbnail(); ?>
       	</a><?php endif; ?></div>
   
       <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
       <?php the_excerpt('Read More &raquo;'); ?>
       </li>
   
       <?php endforeach;
       wp_reset_postdata();?>
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Regan Khadgi](https://wordpress.org/support/users/regankhadgi/)
 * (@regankhadgi)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/get_posts-show-category-title/#post-5829758)
 * Hi there,
 * You can use get_the_category($post_id) to get the category of any post.
    Please
   visit [here](http://codex.wordpress.org/Function_Reference/get_the_category) 
   for more reference.
 * Thanks.
 *  Thread Starter [intricateartist](https://wordpress.org/support/users/intricateartist/)
 * (@intricateartist)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/get_posts-show-category-title/#post-5830003)
 * I’ve added
 * `<h2><?php get_the_category( $post_id ); ?></h2>`
 * Outside the get_posts query and nothing displays.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘get_posts — show category title?’ is closed to new replies.

## Tags

 * [category title](https://wordpress.org/support/topic-tag/category-title/)
 * [get_posts](https://wordpress.org/support/topic-tag/get_posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [intricateartist](https://wordpress.org/support/users/intricateartist/)
 * Last activity: [11 years, 2 months ago](https://wordpress.org/support/topic/get_posts-show-category-title/#post-5830003)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
