Drupal node expire and auto expire removal of ads from publications upon expiration
One essential feature of our Drupal classifieds board will be the automatic unpublishing of listings after a certain period. We'll start by using ready-made modules, and later we'll try implementing this functionality with the Rules module. For this, I found 2 modules for Drupal 6 and 1 for Drupal 7:
- Node expire – Drupal 6
- Auto expire – Drupal 6 and 7
Drupal 6 Node Expire
First, let’s try Node Expire for Drupal 6:
http://drupal.org/project/node_expire
I’ll use version 2.06.
Install and enable the Node Expire module.
This module also requires the Drupal Rules module.
Now we can manage expiration times per content type. Let’s go to edit the content type "Ad":
Here we can specify how long nodes will remain published on the board. Let’s set it to 1 week. Use the following expressions to define dates:
- +1 hour, +2 hours, +n hours
- +1 day, +2 days, +n days
- +1 week, +2 weeks, +n weeks
- +1 month, +2 months, +n months
- +1 month 2 weeks 3 days 3 hours
Let’s try using “1 week”.
Now let’s create a node of the "Ad" content type:
You’ll see an expiration date appear — exactly one week from the current date (today is 2011-12-02).
The module’s readme.txt file contains an importable Rules rule.
Paste the code from readme.txt into the import window:
You’ll now see a new rule which you can edit in the admin UI to filter by content type or change the expiration date logic.
Don’t forget to configure cron to ensure expired ads are unpublished.
Drupal 7 Auto Expire
Download and install the Auto Expire module.
This module doesn’t require any dependencies, so you can use it immediately. Just configure permissions if you want other roles to edit expiration settings.
Go to site configuration and choose Auto Expire:
Let’s go through Auto Expire settings:
- Article – basic Drupal content type (you can choose others).
- Expire – enables expiration functionality for this content type.
- Days – number of days the content remains published.
- Warn – days before expiration to send a notification to the author.
- Purge – days after expiration to permanently delete the node.
Note: As of 2011-12-07, Auto Expire is still in development and not yet production-ready.
Set your values, configure cron, and your ads will automatically unpublish on time.
In the next lesson, we’ll build similar functionality using the Rules module.