Is there a way to get the name of the category and the link to the category page separately inside the wordpress loop. I don't have the id of the category either and I wanna display images instead of category names therefore the_category() doesn't work for me.


Appreciate all the answers...

To store the name of the category instead of outputting it straight to the screen, use get_the_category() to retrieve the categories for the current post. I think getting the link will depend on your permalinks settings:

$current_post_categories = get_the_category(); // store category objects for current post in an array
foreach( $current_post_categories as $category) {
   echo $category->cat_name; // print out the category name
   echo $category->cat_ID; // print out the category ID
   // if your permalinks are set to use the category's name for the URL, use:
   echo '<a href="http://your.wp.domain/'.$category->cat_name.'">this is a link</a>';
   // if you're not using nice links, I think it would be something like:
   echo '<a href="http://your.wp.domain/?cat='.$category->cat_ID.'">this is a link</a>';


Thanx for this code.
It's very usefull.
I wrote it like a function cat_post_title().
It's work perfectly.
I tryed to tweak it, with a category filter.
After 4 hours i had no success...

Anyone have any idea ?

Thanks in advance.