Forums

Show all posts for last 5 days that contained posts (10 posts)

  1. Johnny B
    Member
    Posted 3 years ago #

    At my workplace we are converting from WP v2.0.x to v2.6. One feature from v2.0 that they want brought over to the new version is the ability to show all posts from the last 5 days. Because for some days no posts were published (such as over the weekends), I should qualify this with 'show all posts from the last 5 days that contained posts'. This feature originally existed in v2.0.x in the admin, under the Reading Options/Settings, which would allow the user to select either 'Posts' or 'Days' for the Show at Most setting.

    So far, I have been unable to replicate this feature. I had a look at the v2.0 code, and quickly decided that editing the core files for this is above and beyond my skill. Since we only need this feature for the index page, I was hoping for a quick hack to implement this. One implementation I have been playing around with (pseudocode):

    $posts_per_page = 5;
    query_posts()
    
    while (have_posts(): the_post())
    {
      if (the_time('m.d.Y') for this post == the_time('m.d.Y') for last post)
      {
        $posts_per_page++;
      }
    }
    
    rewind_posts()
    
    query_posts('posts_per_page='.$posts_per_page)
    ...(Show posts, etc.)

    This implementation is not working for me, but perhaps something like this will work? Any thoughts?

  2. Johnny B
    Member
    Posted 3 years ago #

    Hey everyone. I'm still working on this issue, so any input is greatly appreciated. At this point, I am willing to entertain any thoughts, even if not so relevant...

  3. flick
    Member
    Posted 3 years ago #

    Try dropping a note here as well :)
    http://wordpress.org/support/topic/197381?replies=31

  4. Dagon Design
    Member
    Posted 3 years ago #

    I will write some code for you - give me a few mins :)

  5. Dagon Design
    Member
    Posted 3 years ago #

    Ok, here you go:

    http://www.dagondesign.com/files/posts_from_last_x_days_with_posts.txt

    Rename to index.php, and it replaces the index file for the default WordPress theme. Of course, you can take out the code and add it to your own custom theme.

    I may eventually turn it into a plugin, but for now it is just PHP added to the template file to replace the standard loop system. It is fairly basic, and could be re-written several different ways, but it works.

    You can set the number of days near the top, and it will list all posts from the last X days (that contained posts) on your WP home page.

    Hope that works for you :)

  6. flick
    Member
    Posted 3 years ago #

    I will write some code for you - give me a few mins :)

    This is the sort of thing I'd say in my (almost) wildest dreams ;)

  7. @mercime
    Member
    Posted 3 years ago #

    what mosey said :)

  8. Johnny B
    Member
    Posted 3 years ago #

    Dagon Design, this is perfect, thank you so much!

    In searching the forum for a solution to this, I did see a few similar requests, so I believe this would be a helpful plugin. I am modifying your code to suit my needs and will post the modified code soon in case it is useful to anybody.

    Thanks again Dagon, mosey, mercime, and anyone else who read this.

  9. Dagon Design
    Member
    Posted 3 years ago #

    No problem. I made it to use the loop system so you could customize it better, but for the plugin version, it will be slightly different, but should still be customizable. Look for it soon ;)

  10. Dagon Design
    Member
    Posted 3 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic