yeah just add this code in ur sidebar
<?php wp_get_archives('type=postbypost&limit=3'); ?>
this should post the past 3 posts .
Thread Starter
g10r3
(@g10r3)
thank u, but it seems that i get only the title of the post. How che i get the date and the excerpt?
It also seems the shows always the lastest 3 post, while i need to show the previous 3 post of the single post shown in the main area of the single.php
Thread Starter
g10r3
(@g10r3)
If think i’m on the right way.
I’ve found this snippet of code from http://codex.wordpress.org/Function_Reference/WP_Query
// Create a new filtering function that will add our where clause to the query
function filter_where( $where = '' ) {
// posts in the last 30 days
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
return $where;
}
add_filter( 'posts_where', 'filter_where' );
$query = new WP_Query( $query_string );
i’ve managed to the the time of the current post with
global $wp_query;
$post_current_date = $wp_query->post->post_date;
but i don’t know how to change the code above…
i think i have to change “date(‘Y-m-d’, strtotime(‘-30 days’))” with “$post_current_date”, but i’m not able to get it without errors…
for example, this one:
function filter_where( $where = '', $post_current_date ) {
// posts più vecchi dell'attuale
$where .= " AND post_date < '" . $post_current_date . "'";
return $where;
}
add_filter( 'posts_where', 'filter_where', 10, 2 );
$previous_query = new WP_Query( $query_string . "&posts_per_page=3");
gives “Catchable fatal error: Object of class WP_Query could not be converted to string in sidebar.php on line 21”
Any hint? Thank u