Opened 10 months ago
Last modified 9 months ago
#21485 new enhancement
Exclude current post from Recent Posts widget
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Widgets | Version: | |
| Severity: | normal | Keywords: | ux-feedback has-patch |
| Cc: | xoodrew@… |
Description
Checking demo site - http://twentytwelvedemo.wordpress.com/
If you visit any recent post like this one - http://twentytwelvedemo.wordpress.com/2012/03/28/road-trips/
The recent post widget on right sidebar include this post in recent 5 post. We could just exclude present post from the loop using code like this
<?php
global $post;
$args=array(
"numberposts"=>5,
"orderby"=>"post_date",
"post__not_in"=>array($post->ID)
);
$posts = get_posts($args);
foreach($posts as $post) {
setup_postdata($post);
?>
Most theme has it. If you are already in a post which is among recent 5, no point of showing it in the loop.
Attachments (2)
Change History (5)
DrewAPicture — 10 months ago
comment:1
DrewAPicture — 10 months ago
- Cc xoodrew@… added
- Keywords has-patch added
- Summary changed from Twenty Twelve: Exclude Present Post From Recent Post to `
21485.diff Adds a post__not_in value to the WP_Query. Not sure if using get_the_ID() in this instance is cheating :)
comment:2
SergeyBiryukov — 10 months ago
- Component changed from Bundled Theme to Widgets
- Summary changed from ` to Exclude current post from Recent Posts widget
Note: See
TracTickets for help on using
tickets.

Excludes current post