[resolved] Exclude post in sidebar based on selection (3 posts)

  1. cboakes
    Posted 6 years ago #


    I am trying to display posts in a way where the sidebar displays the excerpts of two recent posts and the middle of the page displays the full post when the post in the sidebar is selected. I have been able to do this by modifying the 'single.php' file.

    However I don't know how to exclude the post in the middle from the sidebar?

    Can anybody point me in the right direction on how to do this?



  2. cboakes
    Posted 6 years ago #

    I've figured out what I think is the best way to approach it but I still need help with its completion:
    I use:
    <?php query_posts(array('category_name' => 'news', 'post__not_in' => array(31))); ?>
    This would exclude, in this instance, the post with the ID of 31.

    So now I need to make it dynamic. My knowledge of php isn't great, but I thought declaring a variable of the current post would work, so something like:

    $excludeid = 31;
    query_posts(array('category_name' => 'news', 'post__not_in' => array($excludeid)));

    This worked fine. So to make it dynamic my logic was to go with:
    $excludeid = the_ID();

    But this just doesn't work, would anybody help me to try and make this dynamic?


  3. cboakes
    Posted 6 years ago #

    Figured it out, thanks to this article:


    So the variable needed to be declared as:

Topic Closed

This topic has been closed to new replies.

About this Topic