Support » Fixing WordPress » Show 3 previous posts into a single post page

  • Hi,

    i need to show the 3 previous posts (with title and excerpt) into the sidebar of a single post page.

    There’s a way, with some code or a plugin? I wasn’t able to find anything that seems related…

    Thank u.

Viewing 3 replies - 1 through 3 (of 3 total)
  • yeah just add this code in ur sidebar

    <?php wp_get_archives('type=postbypost&limit=3'); ?>

    this should post the past 3 posts .

    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

    If think i’m on the right way.

    I’ve found this snippet of code from

    // 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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show 3 previous posts into a single post page’ is closed to new replies.