Forums

No repeat posts ( in sidebar ) (4 posts)

  1. venkmanuk
    Member
    Posted 8 months ago #

    Hi there,

    I'm building a custom theme. My sidebar shows 'adverts' that lead to a post in category 5 and the main column shows all other posts and categories except category 5.

    Here's the thing:

    When someone clicks on the post ( 'advert' ) in the sidebar and we go to that post's 'single' page, how can i prevent the post being shown in the sidebar?

    i think the code needs to say:
    if - anything in the sidebar loop = the current page id, skip it.

    does this sound right? how do i do that in php?

  2. venkmanuk
    Member
    Posted 8 months ago #

    bump

  3. alchymyth
    The Sweeper
    Posted 8 months ago #

    what code is used to show the sidebar posts?

    (please follow http://codex.wordpress.org/Forum_Welcome#Posting_Code when posting code)

    generally:

    look into the 'post__not_in' parameter for queries;
    http://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters
    also, read http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action for avoiding duplicate posts;

    only guessing: you might need to use a conditional tag such as is_single(), and add global $post; before the code.

  4. venkmanuk
    Member
    Posted 8 months ago #

    thanks for your reply,
    here's a pastebin of the current code:
    http://pastebin.com/Y81Pxctq

    maybe it'll work to add this! ?

    <?php
    function myPostid() {
    global $wp_query;
    $thePostID = $wp_query->post->ID;
    }
     if ( $post->ID == $thePostID ) continue;
    ?>

Reply

You must log in to post.

About this Topic