WordPress.org

Forums

[resolved] List of entries prior to last entry(s) (6 posts)

  1. ryanoz
    Member
    Posted 8 years ago #

    I can't find a solution to this anywhere on the forum.
    I just can't figure it out on my own.

    I need to display a list of 3 entries prior to the date of the last entry.

    For example, say the last time I posted to the blog was April 15th, and I made 2 posts. I would want to display a list in the sidebar which would be 3 entries made before April 15th.

    Any help, references, examples, ect... would be very appreciated.
    Thank you

  2. ryanoz
    Member
    Posted 8 years ago #

    Anyone?
    uuuuhghghg, this is so stupid. I'm wasting my time.
    The Docs aren't helping, the forum isn't helping.
    How am I suppose to get this done?

    Let me trying something else...
    How would you set a variable to the date of the last post?

    like this?
    <?php
    $last_post_date = get_the_time('F jS, Y');
    ?>

  3. ryanoz
    Member
    Posted 8 years ago #

    query_posts('showposts=5&offset=1');

    something like this will not work because I will not know how many to offset. There could be 1 or there could be 5 posts made on the last entry date.

  4. ryanoz
    Member
    Posted 8 years ago #

    screw it. This is the best I can come up with on my own
    and it doesn't do a damn thing. Unless I get any replies then this is the end of my wordpress experience. All this hard work I've put into designing this blog and now I have to trash the whole thing and disappoint the person I was working on it for. Had a very nice site going too.

    <ul>
    <?php
    $post_month = the_date('m','','', FALSE);
    $post_year = the_date('Y','','', FALSE);
    $post_day = the_date('d','','', FALSE);
    ?>
    
    <?php query_posts("year=$post_year&monthnum=$post_month&day=$post_day&order=DESC"); ?>
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>			 
    
    <?php endwhile; else: ?>
    
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?><br /><span><?php the_time('F jS, Y') ?> - <?php wp_link_pages(); ?> <?php comments_number(__('<strong>0</strong> Comments'), __('<strong>1</strong> Comment'), __('<strong>%</strong> Comments')); ?></span></a></li>
    
    <?php endif; ?>
    </ul>
  5. ryanoz
    Member
    Posted 8 years ago #

    blah

  6. ryanoz
    Member
    Posted 8 years ago #

    Ok, so I'm pretty sure I just figured this out. It is working so far. Thanks to the 0 replies.
    I knew that if I could figure out the total number of posts made on the last post date, then I could just set the 'offset=$number_of_posts". Then, this would enable me to show a list of previous entries prior to the last posting date.
    See this topic on how to get the total number of posts made on the last posting date:
    http://wordpress.org/support/topic/115069?replies=2

    Then... adding this will create a list of 3 entries prior to last posting date.
    So the whole thing looks like this:

    <ul>
    <?php
    $post = $posts[0]; // Hack
    if (is_day()) {
    $likedate = 'Y-m-d ';
    }
    $count = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE post_date LIKE '" . get_the_time($likedate) . "%' AND post_date_gmt < '" . current_time('mysql', TRUE) . "' AND post_status = 'publish'");
    ?>
    
    <?php query_posts("showposts=3&offset=$count"); ?>
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?><br /><span><?php the_time('F jS, Y') ?> - <?php wp_link_pages(); ?> <?php comments_number(__('<strong>0</strong> Comments'), __('<strong>1</strong> Comment'), __('<strong>%</strong> Comments')); ?></span></a></li>
    <?php endwhile; else: ?>
    <?php endif; ?>
    </ul>

    Have no idea how getting $count number works, doesn't read very logical to me, but it works.

    So, thanks to me and the totally irrelevant support topic I was able to stumble upon; I figured it out.

Topic Closed

This topic has been closed to new replies.

About this Topic