WordPress.org

Forums

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

  1. cboakes
    Member
    Posted 5 years ago #

    Hi,

    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?

    Thanks

    Chris

  2. cboakes
    Member
    Posted 5 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:

    <?php
    $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?

    Thanks

  3. cboakes
    Member
    Posted 5 years ago #

    Figured it out, thanks to this article:

    http://www.mydigitallife.info/2006/06/24/retrieve-and-get-wordpress-post-id-outside-the-loop-as-php-variable/

    So the variable needed to be declared as:
    $post->ID

Topic Closed

This topic has been closed to new replies.

About this Topic