Hello,
I'm using getResources to display an overview of newsitems. Works fine.
What I want to achieve is to display a label "New" besides the pagetitle (newsitemtitle) in my getResources overview for each newsitem that is published the last 2 weeks.
Therefore I'm using a snippet I found in Bob's Blog :
http://bobsguides.com/blog.html/2015/03/09/modx-snippet-development-iii/
This works on the page with the full newsarticle
(where I call the snippet in the template), but not on the page with the getResources call results. Here I call the snippet in the tplChunk of the getResources call.
On the page with the getResources call, the snippet takes the publishedon date of the page withe the getResources result instead of the publishedon date of each retrieved resource with a newsitem.
Any idea how to make this work ?
This is Bob's snippet :
/* NewResource snippet */
/* Default return value */
$output = '';
/* Return value for new resources that are published */
$newOutput = '<span class="label">NEW!</span>';
/* Set $interval as the number of seconds in two weeks */
$interval = 1209600;
/* See if the resource is published */
$published = $modx->resource->get('published');
/* For published documents, see if publication date is
within the last two weeks */
if ($published) {
/* Get the current time as a timestamp */
$currentTime = time();
/* Get the publishedon date (if any) and
convert it to a unix timestamp */
$ptime = strtotime($modx->resource->get('publishedon'));
/* Get the resource's age in seconds */
$age = $currentTime - $ptime;
if ($age < $interval) {
/* Yes, it's recent - return NEW! */
$output = $newOutput;
}
}
return $output;