Quantcast
Channel: help – WordPress.org Forums
Viewing all articles
Browse latest Browse all 13924

Richard Aber on "How i show category name using post_meta in functions.php?"

$
0
0

From the Codex entry for get_the_category:

Returns an array of objects, one object for each category assigned to the post.

So, you would need to assign the result of get_the_category to a variable. Then you would either output the first category name, or loop through the array to output each category name.

Here is an oversimplified example, only outputting the first category name:

$category = get_the_category();
echo '<p class="post_meta">by ' . get_the_author() . ' | Posted In: ' . $category[0]->cat_name . ' | ' . get_comments_number() . ' comments</p>';

Viewing all articles
Browse latest Browse all 13924

Trending Articles