[SOLVED] Help needed with code to show 'New' icon in News Module
[SOLVED] Help needed with code to show 'New' icon in News Module
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.
Last edited by dvanoss on Thu Oct 30, 2008 9:12 pm, edited 1 time in total.
Re: Help needed with code to show 'New' icon for latest articles in News Module
You should be able to do this within the template, using some smarty logic.
Nullig
Nullig
Re: [SOLVED] Help needed with code to show 'New' icon in News Module
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:
In the News template displaying the article titles I added:
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
//
{if ($entry->postdate|date_format:"%Y-%m-%d") > ($lastweek|date_format:"%Y-%m-%d")}
{/if}