I'm novice on wordpress development and I have this problem.

How can I show the post category name?


Post Title: Wordpress Rules! Post author: Irwin R. Post Date: 22/09/2014 Cat Name: Wordpress

I'm using the following code:

query_posts(array('cat' => 5, 'posts_per_page'=> 3, 'orderby' => 'ASC'));
while (have_posts()) { the_post(); 
<h3>Post Title: <?php the_title();?></h3>
<h3>Post Author: <?php the_author();?></h3>
<h3>Post Date: <?php the_date();?></h3>
<h3>Cat Name: // What function should I use here?</h3>

I'll appreciate your help!

  • 2
    You will have to use <?php the_category(', '); ?> and as suggested below, never use query_posts. Use WP_Query instead.
    – Robert hue
    Commented Sep 22, 2014 at 14:24
  • Thanks Robert, it's works but i have another problem. I have one category and one subcategory, then the result shows both categories and i want just the subcategory. (e.g) Cat Name: Development SubCat name: Wordpress I want to print just SubCat Name.
    – Irwin
    Commented Sep 22, 2014 at 14:37
  • 1
    Please search the site I'm 99.99% sure that what you has been answered before. Commented Sep 22, 2014 at 15:20
  • 1
    You should have a read here. This might help Commented Sep 22, 2014 at 15:22
  • If the answer was helpful to you, then consider accepting it. See »What should I do when someone answers my question?« and/or »Why is voting important?«, more information about the WordPress Development model is available at the help center. Commented Apr 28, 2015 at 14:30

1 Answer 1


There is: the_category(), which not only seems to be all to fittingly named.

Aside from that, don't use query_posts, as for the why take a look at those two threads:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.