I need a snippet to drop in the PHP section of a custom block's settings. It will display the block on nodes, based on their published date.

The goal is to create a block that will show only on pages older than a certain amount. For example, at least six months older than today's date.

$75 Paypal'd immediately to the good Samaritan who can turn this around quick. I'm at email scienceblog@gmail.com

Comments

JaredAM’s picture

What you simply need to do is in the block visibility settings add:

<?php

if ($node = menu_get_object()) {
  return ($node->created < time()) ? TRUE:FALSE;
}

?>

You can replace the php function time() with whatever time period you want. For example, if you want the block to show up for posts older than 2 weeks you can use

<?php 
  $node->created < strtotime('-2 weeks')
?>

Note: menu_get_object will allow you to specify a specific node type if needed (http://api.drupal.org/api/function/menu_get_object/6). It defaults to "node" which should cover pretty much everything.

Let me know if this works for you,
Jared