[SOLVED] Help needed with code to show 'New' icon in News Module

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
dvanoss
Forum Members
Forum Members
Posts: 46
Joined: Mon Dec 18, 2006 9:21 pm

[SOLVED] Help needed with code to show 'New' icon in News Module

Post 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.
Last edited by dvanoss on Thu Oct 30, 2008 9:12 pm, edited 1 time in total.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm
Location: Comox Valley, BC

Re: Help needed with code to show 'New' icon for latest articles in News Module

Post by Nullig »

You should be able to do this within the template, using some smarty logic.

Nullig
dvanoss
Forum Members
Forum Members
Posts: 46
Joined: Mon Dec 18, 2006 9:21 pm

Re: [SOLVED] Help needed with code to show 'New' icon in News Module

Post 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}
Post Reply

Return to “Modules/Add-Ons”