Forums

Parent ID for Post in Loop (3 posts)

  1. joenewbreed
    Member
    Posted 5 years ago #

    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.

  2. Bryan Davis
    Member
    Posted 5 years ago #

    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

  3. Storyman
    Member
    Posted 4 years ago #

    moved post

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.