understanding get_the_category(), multiple cats, and parents
-
Hello,
I’m creating a breadcrumb script, and need to understand how to get parent category IDs and names of a category and post. This seems to get complicated as a post can be in multiple categories, including the parent category itself.For discussion, let’s say I have the following categories:
12 – Beastly Cat
20 — Ratty Cat
21 — Black Cat
22 — Runt CatBeastly Cat, Ratty Cat, Black Cat, and Runt Cat all share a single post titled, “Scratch Post”.
If I’m at “Scratch Post”, get_the_category($cat) (once I get $cat) returns an array of all the cats. This makes sense, but may cause challenges with my breadcrumb scheme.
If I’m at /?cat=12, get_the_category($cat) returns an array of all the cats as well. Eh? I think this is because the page is listing “Scratch Post” on the page. However, I just want info for the current category and eventually any parent cats that cat belongs to.
Would I do a custom database query for this? Would I treat is_single scripts different than is_category scripts? How would I get started?
Thanks for the assist. ??
- The topic ‘understanding get_the_category(), multiple cats, and parents’ is closed to new replies.