Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm stuck in a rather simple task: to get the category title for the current post, within the loop, to be used in the function (not to be automatically printed). Any ideas?

share|improve this question
1  
what do you mean with 'to be used in the function' ? is this what you want: codex.wordpress.org/Function_Reference/get_the_category –  Michael Apr 4 '12 at 21:05

1 Answer 1

up vote 2 down vote accepted

The function get_the_category() returns an array of category objects. To get the name of the first category, use this:

$categories = get_the_category(); 
$cat_name = $categories[0]->cat_name;

For a list of the properties of the category object, see the documentation on get_the_category()

share|improve this answer
    
Oh, god. It returned an array.. of course! And I completely forgot to sprint_f it, to make things worse. I'm such a bad programmer sometimes.. thanks for the help! –  João Ramos Apr 5 '12 at 15:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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