Opened 10 months ago

Last modified 9 months ago

#21485 new enhancement

Exclude current post from Recent Posts widget

Reported by: Asif2BD 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)

21485.diff (908 bytes) - added by DrewAPicture 10 months ago.
Excludes current post
21485.2.diff (960 bytes) - added by DrewAPicture 10 months ago.
+ Readability

Download all attachments as: .zip

Change History (5)

Excludes current post

  • 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 :)

+ Readability

  • Component changed from Bundled Theme to Widgets
  • Summary changed from ` to Exclude current post from Recent Posts widget

If I had to guess, one reason why not to do this would be it would make caching harder.

Note: See TracTickets for help on using tickets.