WordPress code
Someone at the WP Forums asked how one would list 5 most recent posts but not the current post if it was one of the most recent ones… So, this is what my brain spouted out:
<?php
if( get_query_var(‘p’) ) {
$current = get_query_var(‘p’);
} else {
$postname = get_query_var(‘name’);
$current = $wpdb->get_var(“SELECT ID from $wpdb->posts WHERE post_name = ‘$postname'”);
}
print “<ul>”;
$count = 0;
$posts = get_posts(‘numberposts=6’);
foreach ($posts as $post) :
setup_postdata($post);
global $id;
if ( $count < 5 and $id != $current ) { ?>
<li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li>
<?php
$count++;
}
endforeach;
print “</ul>”;
} ?>