Forums

Need the author ID outside the loop (2 posts)

  1. RenFromPenn
    Member
    Posted 3 years ago #

    I am trying to display different information in my sidebar depending on which authors single post is being displayed. I have run into trouble, however, since the sidebar is outside the loop. How can I retrieve the author ID in this scenario?

    Here is the code that I was trying to use until I realized that it was outside the loop.

    $post_id = $post->ID;
    $post_author = get_post($post_id);
    $author = $post_author->post_author;
    if ($author == "2"){
    echo '1234';
    } elseif ($author == "3"){
    echo 'QQQQ';
    } else {
    echo 'abcd';
    }

  2. equaldesign
    Member
    Posted 3 years ago #

    Can't you have your sidebar in the loop? It is in the default theme and in many of my themes.

Topic Closed

This topic has been closed to new replies.

About this Topic