• joenewbreed

    (@joenewbreed)


    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Parent ID for Post in Loop’ is closed to new replies.