Ok, I'm trying to make a theme in which each post uses a different CSS class depending on the parent category.
So what I need is a way to get the Parent ID # for a post from within The Loop.
Anyone have any ideas? I'm going insane here.
Ok, I'm trying to make a theme in which each post uses a different CSS class depending on the parent category.
So what I need is a way to get the Parent ID # for a post from within The Loop.
Anyone have any ideas? I'm going insane here.
Something like this might do the trick:
$cat = get_the_category();
if ($cat->cat_parent = 0) {
$cat_parent = $cat->cat_ID;
} else {
$cat_parent = $cat->cat_parent;
}
echo $cat_parent; // add that into the class/id of your post
Certainly your solution will involve get_thecategory() which you can look up in the Codex
moved post
This topic has been closed to new replies.