Archive for the ‘Technology’ category

Dealing with Expiry Content in Drupal

April 13th, 2010

Whenever there’s an event, or announcement that’s happening tonight or the next morning, or even in the next few days, usually I will create a block and post the content and then later I will disable the block. Imagine how many blocks that will be listed under Disabled Blocks section. Furthermore, I have to make sure that I remember to disable the block when it’s no longer important to have the content on my site. As a result, I will have more blocks and loading the blocks administration page consumes more memory and it becomes hard to organize it.

I come up with one way of automating the process of publishing expiry content without installing extra modules and PHP usage:

Create a content type called Expiry Content, name it anything you like.

Under Content Management -> Content Type ->Add New Content Type

In the Fields section, add a new date field called Expiry Date. We will use this field to set some future time we want the content to expire

Tips: Lower the sitemap priority adjustment for this content type if you have installed the module. You don’t need search engine results for such a content

Create and Configure a List View Based on The Expiry Content Type

Here, we don’t need to provide a page view, a block suffices. Set the Nodes Per Block to 1.

In the Fields section, get the required fields, usually body is enough. We don’t need title here as we can customize the block’s title later.

In the Filters section, include a node type and select Expiry Content, include Node: Published and set to Yes. Include also the Expiry Date field we created earlier. Under Operator section for this particular field, use Greater Than and under Option, type Now. Whenever the expiry date becomes less than the current time, the content is not visible in the block, literally it expires. This doesn’t mean the content automatically¬† gets unpublished.

At this step, we can go ahead and publish new expiry content.

  1. Content Management ->Create Content > Expiry Content.
  2. Set the Expiry date for the content in the publishing administration.
  3. Edit the title of Expiry Content block in the blocks admin
  4. Make the block available on any page that you want to feature the content