0

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

How can I show the post category name?

Example:

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

I'm using the following code:

<?php
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>
<?php       
}
wp_reset_query();
?>      

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 Sep 22 '14 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. – user3552695 Sep 22 '14 at 14:37
  • 1
    Please search the site I'm 99.99% sure that what you has been answered before. – Nicolai Sep 22 '14 at 15:20
  • 1
    You should have a read here. This might help – Pieter Goosen Sep 22 '14 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. – Nicolai Apr 28 '15 at 14:30
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, privacy policy and cookie policy

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