Matthew Trevino's Scarform
this.isn't.it.

Sort by modified date

Using a simple loop query, you can sort your posts by the modified time/date. You can implement this, really, in any way you see fit.

To add a 2nd loop on top of your primary loop in index.php (or anywhere the loop is used) without calling duplicate posts, place this code above your main loop code:

1
2
3
4
5
6
7
	<?php $my_query = new WP_Query('orderby=modified&posts_per_page=1');
	while ($my_query->have_posts()) : $my_query->the_post();
	$do_not_duplicate = $post->ID;?>
	<!-- post content/date/etc. code goes here... -->
	<?php endwhile; ?>
	<?php if (have_posts()) : while (have_posts()) : the_post(); 
	if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>

What this code will essentially do is create a secondary loop on top of your primary loop that will display all posts that were recently modified followed by your “primary” loop, which will display all posts as they would normally appear, minus your modified posts.

You can change the number to any number you see fit to display of modified posts to display to any number you see fit, really.

What the code is doing:
–Is the post a new post?
—Yes (display at top)
–Has the post been modified?
—Yes (display above newest post)




required



required - won't be displayed


Your Comment:

Posted: November 28th 2009
Category: Code Snippets
Tags: ,

8:47:46: “someone just told me there an explosion…”

Previous Entry

Bob’s a dick.

Next Entry

Archives
Categories