WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Stop sidebar content from showing when on that post (16 posts)

  1. Ryan Paul
    Member
    Posted 5 years ago #

    Hello...

    On my blog I use one of those fake loops to display a post of Youtube video from a 'Hot Video' category in the sidebar.

    When I'm on the single post view... it shows the video in the main area (where it's supposed to) AND in the sidebar (where I don't want it to show).

    If you go to the following URL you'll see what I mean:
    http://www.ryanpaul.ca/hot-video/griffin-house-the-guy-that-says-goodbye-to-you-is-out-of-his-mind/

    Anyone have an idea how I can stop the sidebar vid showing when on that post's single post view?

    I tried assigning the post id to a global variable in the main loop, then assigning the post id to a different variable in the sidebar, and then doing <? if($mainid == $sideid) { ?> in the sidebar but none of that worked.

  2. MichaelH
    Member
    Posted 5 years ago #

    $post->ID would typically be holding the current post. Might need global $post in your sidebar.php.

  3. Ryan Paul
    Member
    Posted 5 years ago #

    In sidebar.php I have this:

    <?
    global $post;
    $sideid == $post->ID;
    if ($sideid != $mainid) {
    ?>Fake Loop & Video Here<?php } ?>

    and then at the bottom of single.php I have:

    <?php
    global $post;
    $mainid == $post->ID;
    ?>

    I've tried putting both these inside and outside the loops... but it still shows the video in the sidebar when viewing the main single post.

  4. MichaelH
    Member
    Posted 5 years ago #

    Sorry, don't understand what you are trying to accomplish.

  5. Ryan Paul
    Member
    Posted 5 years ago #

    On this page for instance...

    http://www.ryanpaul.ca/hot-video/griffin-house-the-guy-that-says-goodbye-to-you-is-out-of-his-mind/

    I don't want that video to show in the sidebar when I'm viewing that page, but DO want it to show when I am NOT on that page.

    The aim is to not have two of the same video showing on screen.

  6. MichaelH
    Member
    Posted 5 years ago #

    So you always want the SAME post/video in the sidebar unless it is the post being show in the single.php view?

  7. Ryan Paul
    Member
    Posted 5 years ago #

    I want the latest post from the Hot Video category to show in the sidebar...

    But I don't want it to show if the post on the side is the same as the post in single.php view :)

    So I can avoid having the same post / video show twice.

  8. MichaelH
    Member
    Posted 5 years ago #

    It will be something in what you call your fake loop:

    if (is_single()) && $post->ID != $id_of_post_in_your_fake_loop {
    //display your post
    }

    If necessary paste that sidebar code in a pastebin and report the link back here.

  9. Ryan Paul
    Member
    Posted 5 years ago #

    The problem is I can't get the id of the side post to cross over into the main loop...

  10. Ryan Paul
    Member
    Posted 5 years ago #

    The problem is I can't get the id of the side post to cross over into the main loop and vice versa... even with using global.

  11. Ryan Paul
    Member
    Posted 5 years ago #

    The code I have in the sidebar that shows 1 post from the video category is as follows:

    <?php query_posts($query_string); query_posts("showposts=1&cat=21"); ?><?php while (have_posts()) : the_post(); ?>
    
    <div class="right-margin">
    <?php the_content();  ?><?php edit_post_link('Edit', '<p>[ ', ' ]</p>'); ?>
    
    </div>
    <?php endwhile; ?>

    I want something like this:

    <?php if($fakeloop-postid != $mainloop-postid) { ?>
    
    <?php query_posts($query_string); query_posts("showposts=1&cat=21"); ?><?php while (have_posts()) : the_post(); ?><div class="right-margin"><?php the_content();  ?><?php edit_post_link('Edit', '<p>[ ', ' ]</p>'); ?></div><?php endwhile; ?> 
    
    <?php } ?>
  12. MichaelH
    Member
    Posted 5 years ago #

    Then just exclude the post in single with

    $args = array(
    	'showposts' => 1,
    	'post__not_in' => array($post->ID),
    	'cat' => '21'
      );
    query_posts($args);
  13. Ryan Paul
    Member
    Posted 5 years ago #

    DUDE YOU ROCKKKKKKKK!

    That worked - nearly. But now it ignores the 'more' tag I've inserted into the post... so when I view ANY page or post on my website, it shows the entire text of the sidebar video.

    :(

  14. MichaelH
    Member
    Posted 5 years ago #

    See the note about the more
    Template_Tags/the_content

  15. Ryan Paul
    Member
    Posted 5 years ago #

    That's weird because it DOES work if I don't use the code you gave me.

    At the moment I'm hiding the overflow on the div with css.

    This sucks because I want a more link below the side vid and can't now :(

  16. Ryan Paul
    Member
    Posted 5 years ago #

    Actually I think this way worked out better... check it out

    http://www.ryanpaul.ca/

Topic Closed

This topic has been closed to new replies.

About this Topic