views:

41

answers:

1

So each post it will be posted in one category, and for each post I want to get the posted in category permalink, only the URL without markup. How can I do that?

//Explained again

Well the post is posted in a category, right? Well I need to show that category, but not the name of the category, the url for that category.

+1  A: 

I would use get_the_category(), which will return an array of objects, one for each category. In your case, you'll get an array containing one object back, because you only have one category. Then use get_category_link() to turn the ID of the category into a URL.

So, if you're in The Loop, I would do something like this (NB: untested!)

$categories = get_the_category();
$url = get_category_link($categories[0]->cat_ID);

Obviously, you'll want to make sure this doesn't fall on its backside if there are no categories assigned, for example.

This is similar to what WordPress does if you include a category in your permalink structure -- it will get the category with the lowest numeric ID and use that in the permalink.

Matt Gibson
Works, thanks a lot!
Uffo