Page 1 of 1
[SOLVED] Help needed with code to show 'New' icon in News Module
Posted: Tue Oct 28, 2008 10:11 pm
by dvanoss
I would like to display a 'New' icon in an article that has a post date of 7 days or less so our users can see if anything is new or updated. I would expect I'd have to determine if 'formatpostdate' is, for example, 7 days or less than the current date, and if so, to display an icon, but I'm not sure if I need to change something in the hard code or if I can accomplish it within a News template, and how to get the current date info.
Re: Help needed with code to show 'New' icon for latest articles in News Module
Posted: Tue Oct 28, 2008 10:14 pm
by Nullig
You should be able to do this within the template, using some smarty logic.
Nullig
Re: [SOLVED] Help needed with code to show 'New' icon in News Module
Posted: Thu Oct 30, 2008 9:11 pm
by dvanoss
I decided to dig into Smarty coding and came up with a solution. I had to add two variables in modules/news/action.default.php; one to give the article posting date and one to give a date of a week minus the current date in order to calculate if an article was less than 7 days old:
Code: Select all
// added variables to display a NEW icon if the article was posted less than 7 days ago
$onerow->postdate = $row['news_date']; // date of the posting
$smarty->assign('lastweek', strtotime('-1 week')); // gives today minus one week
//
In the News template displaying the article titles I added:
{if ($entry->postdate|date_format:"%Y-%m-%d") > ($lastweek|date_format:"%Y-%m-%d")}
{/if}