Update:
I have converted this into a plugin, which you can download here.
If you'd rather use it as a UDT, this is the code, which I have named FreshContent
Code: Select all
global $gCms;
$db =& $gCms->GetDb();
// The alias of the page to check
$the_alias = isset($params['alias']) ? $params['alias'] : "";
// Max number of days for a page to be considered "fresh"
$the_days = isset($params['days']) ? $params['days'] : "";
// HTML that will be output if page is at least x days "fresh"
$the_output = isset($params['output']) ? $params['output'] : "";
$query = "SELECT modified_date FROM ".cms_db_prefix()."content WHERE content_alias=?";
$row = $db->GetRow($query, array($the_alias));
if($row)
{
$last_mod = strtotime($row['modified_date']);
$today = time();
$date_diff = floor(($today - $last_mod)/86400);
if ($date_diff < $the_days)
{
return $the_output;
}
}
else
{
return "Content page not found, check the page <em>alias</em>.";
}
alias = the alias of the page in question
days = max number of days for a page to be considered "New"
output = the html to be output if a page is "New"
Usage:
Code: Select all
{FreshContent alias='home' days='14' output='<img src="new.gif" />'}
The output can be any HTML, another example would be:
Code: Select all
<li {FreshContent alias='home' days='14' output='class="new_item"'}>
<a href="index.php/home">Home Page</a>
</li>
Code: Select all
{FreshContent alias=$node->alias days='5' output='<img src="star.gif" />'}
One more example:
Code: Select all
</__body>
{FreshContent alias=$page_alias days='8' output='<div class="notice">This page is new!</div>'}
...
As you can see, there's many possibilities with this simple UDT. I am making this UDT into a Plugin and will soon bee posted on the forge.