[wp-hackers] Problem getting categories

Jeremy Clarke jer at simianuprising.com
Mon May 10 17:54:58 UTC 2010


On Mon, May 10, 2010 at 1:33 PM, Brian Fidler <fidler.brian at gmail.com>wrote:

> my url string looks like this:
>
> http://www.mysite.com/paintings/collection1/post-name
> http://www.mysite.com/prints/collection3/post-name
>
>
You're asking for trouble using categories in your URLs. It shouldn't affect
the issue you mention below, but I recommend against this pattern if there
is any way you can avoid it. WP is not well designed for for category based
post urls compred to dates.

Have you considered using "Pages" instead of posts? It looks like that would
be a logical way to organize your collections of paintings and prints and by
making them children you'd get your desired URL structure.


> I'm trying to get the categories using this:
>
> $categories = get_the_category($post->ID);
> echo $categories[0]->cat_name;
>
> It gets the parent category (category[0]) without any problem however it
> isn't getting child categories at all.
>
>
That looks like it should work. Did you try print_r($categories) to see
what's inside?

-- 
Jeremy Clarke | http://jeremyclarke.org
Code and Design | http://globalvoicesonline.org (recently redesigned!)


More information about the wp-hackers mailing list