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 Tuesday, August 26th, 2008 at 8:20pm

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

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. The built in WordPress functions already work if you just want a list of posts from the last set number of days.

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

    It could be a great feature for future versions hehe

  3. 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_

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

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

  6. sorry I forgot to use the code tags.

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

    Am i doing something wrong?

    Thanks!

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