Reibusu
Reibusu

Reputation: 57

How do I remove the most recent post from the sidebar in Wordpress?

On both the front page and the blog page - the sidebar shows the most recent post, which I find doesn't look very good duplicated against the same post expanded on the main page.

This is my code for the sidebar:

<div class="blog-sidebar">
<?php query_posts('showposts=5'); ?>
<?php while (have_posts()) : the_post(); ?>
    <div class="blog-sidebar-feature">
        <?php if ( has_post_thumbnail() ) { ?>
            <div class="blog-sidebar-image"><a href="<?php the_permalink() ?>" rel="bookmark" title=""><?php the_post_thumbnail('medium'); ?></a></div>
        <?php
        }
        ?>
        <div class="blog-sidebar-content">
            <p class="date"><?php the_time('F j, Y') ?></p>
            <h3 <strong><?php

    foreach((get_the_category()) as $category) { 
echo $category->cat_name . ' '; 
    } 
    ?></strong></h3>
    <h2 <p><a href="<?php the_permalink() ?>" rel="bookmark" title=""><?php the_title();         
    ?></a></p></h2><?php echo get_excerpt(166); ?>
        </div>
    </div>
<?php endwhile;?>
<br />
<?php wp_pagenavi(); ?>
</div>

and the relevant code for how the blog appears on the home page:

<div class="blog-sidebar">
    <div class="blog-sidebar-feature">
        <?php query_posts('orderby=date&order=DESC&showposts=2'); ?>
            <?php while (have_posts()) : the_post(); ?>
            <?php if ( has_post_thumbnail() ) { ?>
                <div class="blog-sidebar-image"><a href="<?php the_permalink() ?>" rel="bookmark" title=""><?php the_post_thumbnail('medium'); ?></a></div>
            <?php
            }
            ?>
            <div class="blog-sidebar-content">
                <p class="date"><?php the_time('F j, Y') ?></p>
            <h3 <strong><?php
    foreach((get_the_category()) as $category) { 
echo $category->cat_name . ' '; 
    } 
    ?></strong></h3>
                <h2 <p><a href="<?php the_permalink() ?>"    
    rel="bookmark" title=""><?php the_title(); ?></a></p></h2><?php echo get_excerpt(166); ?>
            </div>
        <?php endwhile;?>
    </div>

</div>
<div id="connect">
    <?php query_posts('page_id=1');
      while (have_posts()): the_post();
      the_content();
  endwhile;
  wp_reset_query(); ?>
</div>

Is there any way to remove only the most recent post from the sidebar when it appears in full on the main container? Thanks in advance for any help.

Upvotes: 1

Views: 739

Answers (2)

user850010
user850010

Reputation: 6359

UPDATE V2

So you do want recent posts, just not the post currently showing in the main content.

UPDATE V3:

This should work now. I had to change arguments of query_posts to array to make it work.

Try it now:

<?
global $wp_query;
$skip_posts=array();
if (is_single()) //only exclude posts when single post is shown
$skip_posts[]=$wp_query->post->ID;
?>
<?php query_posts( array( 'showposts'=>5,'post__not_in'=>$skip_posts)); ?>

Upvotes: 1

Reibusu
Reibusu

Reputation: 57

<?php query_posts('posts_per_page=5&offset=1'); ?>

Thanks to 850010 for all the help, I went back and had a look at the offset rule and the 'array' wasn't needed. Deceptively simple.

Upvotes: 1

Related Questions