Welcome to Dagon Design. In addition to free scripts, WordPress plugins, and articles, we offer a variety of services including custom theme design, plugin creation, and PHP scripting. Contact me for more information.

Version 1.0   Updated Sunday, February 22nd, 2009 at 2:14pm

Posts from Last X Days Plugin for WordPress

This WordPress plugin displays all posts from the last X days that contained posts. You can define the display template used to generate the list, choosing what data to display by inserting tags. Future-dated and private posts are hidden by default. This plugin can be called from a post or page, or directly from your theme’s template file, adding it to the sidebar, or wherever else you like.

Keep in mind, that this plugin does not list all the posts from the last X days, but rather the last X days that contained posts. For example, if you have it show the last 3 days, but you only have once post a month, it will list the latest 3 posts, because those were the latest 3 unique dates containing posts.

Download

  If you have found this page useful, please consider donating. Thanks!

Installing

  • Download the above file, rename it from .txt to .php, and upload it to your plugins directory.
  • Enable the plugin.
  • Configure the plugin options (under DDLastXDays).

Usage

There are two ways you can use this plugin. In both usage methods, ‘X’ is the number of days you would like to display posts from.

1) In a post or page, insert the following line:

<!-- lastxdays X -->

2) In a template file, insert the following code:

<?php echo lastxdays_generate(X); ?>

Important: If you use the first method, make sure you add this using the html/code editor in WordPress, not the visual editor. In new versions of WordPress, just click the ‘html’ button above the edit box. If you use the visual editor it will not work, as the actual code you entered will be seen on the page, instead of being processed by the script.

Change Log

  • 08-26-08 Version 1.0 – First release.

Options

Here are the options available on this plugin’s options page in the WordPress admin panel.

The default plugin options show a basic example of the template system, which should help make sense of it.

Hide private posts

If enabled, password-protected posts will be hidden.

Hide future-dated posts

If enabled, posts that have been dated in the future (to display on the site later) will be hidden.

Code added before list

This is the HTML that will be shown before the list generation.

Template code

This block of code is repeated for each post. You can also add the special tags, which will display the data about the post.
Tags: %POST_AUTHOR% %POST_DATE% %POST_TITLE% %POST_URL%

Code added after list

This is the HTML that will be shown after the list generation.

Date format for %POST_DATE%

This allows you to customize the date/time format for posts, when you are using this tag in your template. It uses the standard PHP date format.

  1. 15
    KerberosX

    Hi,

    Great plugin, but I am looking for something a bit different. I would like to have something like this on my homepage.

    Thursday, March 4th 2010
    - 22h40 Post 1
    - 16h12 Post 2
    - 12h50 Post 3

    Wednesday, March 3th 2010
    - 19h50 Post 1
    - 14h45 Post 2
    - 11h45 Post 3

    etc…

    So basically I would like to have for instance all posts of the last 5 days, but they should be categorized under the date of the day the were published.

    It’s for a news site. Any idea if this functionality can be embedded in your plugin, or do you know I can accomplish this somehow with the standard codex?

  2. Can we select only certain categories.

  3. Nick: No, this plugin only works with WordPress. There are a lot of phpBB plugins out there – you might ask in the phpBB support forum.

  4. 12
    Nick

    Can this be used like on a phpbb forum page?

  5. This plugin has been tested, and works, in the latest release of WordPress – 2.8

    Jeff: Try this: http://wordpress.org/support/topic/250766

    Krylo: Not sure what the problem could be – did you try reinstalling the plugin?

  6. Hey Dagon, you mention in comment 7 that the built-in Wordpress functions will allow posts from a set number of days. I’ve scoured everything in the Wordpress codex, but can’t seem to find a solution. I’m thinking there must be something I can do in the loop, or a plugin that will let me set a variable “x number of days” in an option. Could you point me in the right direction?

    I’d really like to use your plugin, but it provides a list of posts, whereas I’m looking to display x number of days of full posts on my main index page.

  7. 9
    Krylo

    Hi, I can’t seem to get the plugin to save when I click “update options” I’m using wp 2.7.1

  8. This plugin has been tested in the latest release of WordPress (2.7.1)

  9. The built in WordPress functions already work if you just want a list of posts from the last set number of days.

  10. haaa Ok.. I see, I’m sorry then :S

    It could be a great feature for future versions hehe

  11. That is how it is supposed to work. It does not generate a list of posts from the last 30 days, but a list of posts from the last 30 days _that had posts_

  12. Nope.. it’s giving me posts until 3 month ago beacause my last 30th post is from that date…

  13. Well are those posts on 30 different days? If so, it is working properly.

  14. sorry I forgot to use the code tags.

    <!-- lastxdays 30 --> will give me the last 30 posts

    Am i doing something wrong?

    Thanks!

  15. Hi! I tried to use your plugin but it shows me the last XX posts instead of the posts of the last XX days…

    will give me the last 30 posts..

Leave a Comment

Before you comment: If you are having an issue with a script, please make sure you have read the entire article. Also, please read through the comments because most common issues have already been discussed many times. Thanks.


Be sure to wrap all code in <code></code> tags.