WordPress.org

Ready to get started?Download WordPress

Forums

exlude a post from recent post widget (1 post)

  1. DarknessXI
    Member
    Posted 3 years ago #

    I would like to exclude the post you're currently viewing from the list of recent posts in sidebar

    I try to modify this code in wp-include/default-widget.php

    <ul>
    		<?php  while ($r->have_posts()) : $r->the_post(); ?>
           	<li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>
    		<?php endwhile; ?>
    		</ul>

    in this way

    <?php $pi=$post->ID; ?>
    <ul>
            <?php  while ($r->have_posts()) : $r->the_post(); ?>
            <?php if($pi!=the_ID()) { ?>
           	<li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>
            <?php } ?>
    		<?php endwhile; ?>
    		</ul>

    but it don't work
    What is the solution?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.