Page 1 of 1

News Summary Filter by Date for Monthly Archives - please help?

Posted: Sat Jul 11, 2009 9:07 pm
by ljonizuka
I can't get this code in a news summary template to give me what I want...I'm calling it here:
http://www.runwashington.com/test/?news_by_month=03 with this:

Code: Select all

{news summarytemplate='datetest' number='10'}
===================================
News Summary template called 'datetest'
===================================

Code: Select all

{if $smarty.get.news_by_month}
   {capture assign=news_by_month}{$smarty.get.news_by_month}{/capture}
{else}
   {capture assign=news_by_month}01{/capture}
{/if}

<!--  News datetest (in Summary Template) -->
<div class="NewsSummary">
<b>{$news_by_month}</b>
{foreach from=$items item=entry}

{if $entry->postdate|date_format:'%m' == $news_by_month|date_format:'%m'}	
<p><span class="postdate">{$entry->formatpostdate|date_format:"%m/%d/%y"}</span> 
{$entry->titlelink}<br /><i>{eval var=$entry->summary|truncate:100}</i></p>
{/if}

{/foreach}
</div>
The smarty get is working...but the filter isn't. Client really wants the ability to browse articles by month.

Any help is sincerely appreciated!
Thank you, Lisa

Re: News Summary Filter by Date for Monthly Archives - please help?

Posted: Sat Jul 11, 2009 10:28 pm
by Jeff
$news_by_month|date_format:'%m'
The date_format is expecting a full date not just a month. Try :

Code: Select all

{if $entry->postdate|date_format:'%m' == $news_by_month}	

Re: News Summary Filter by Date for Monthly Archives - please help?

Posted: Sun Jul 12, 2009 11:15 pm
by ljonizuka
Ok, I tried that without luck (no results showing) so I'm trying a full date that I know has three news articles:

Code: Select all

{if $entry->postdate =='2009-07-04'}	
<p><span class="postdate">{$entry->formatpostdate|date_format:"%m/%d/%y"}</span> 
{$entry->titlelink}<br /><i>{eval var=$entry->summary|truncate:100}</i></p>
{/if}
Still no results...any ideas?

Re: News Summary Filter by Date for Monthly Archives - please help?

Posted: Mon Jul 13, 2009 12:49 am
by Jeff
Try putting {$entry->postdate|date_format:'%m'} or {$entry->postdate} in your template to see what they are outputting/they equal.

Re: News Summary Filter by Date for Monthly Archives - please help?

Posted: Mon Jul 13, 2009 1:24 am
by ljonizuka
Thank you so much for your reply. It pointed me in the right direction! The reason it didn't work before was that I had a number limit (only ten) on the records being returned. I've taken that off and now it's working, though painfully slowly...

I'm running two if statements, first to check for month and then for current year - but it's iterating through thousands of articles - it would sure be better to query with the filter instead of filtering all the results from the entire query - ugh.

News Summary Filter by Date for Monthly Archives [SOLVED!?]

Posted: Mon Jul 13, 2009 1:47 am
by ljonizuka
Here it is working, in action. I removed the second if check but it is still running slow...but at least it works, doesn't require mucking around with and module code, and hopefully visitors won't dig around the archives too often and encounter that dragging...

http://www.runwashington.com/newsindex/regionalnews/2009-news-archive.htm

Here is the code I created in a news summary template:

Code: Select all

{if $smarty.get.news_by_month}
   {capture assign=news_by_month}{$smarty.get.news_by_month}{/capture}
{else}
   {capture assign=news_by_month}01-09{/capture}
{/if}

<!--  News datetest (in Summary Template) -->
<div class="NewsSummary">
<b>{$news_by_month}</b>
{foreach from=$items item=entry}

{if $entry->postdate|date_format:'%m-%y' == $news_by_month}
<p><span class="postdate">{$entry->formatpostdate|date_format:"%m/%d/%y"}</span> 
{$entry->titlelink}<br /><i>{eval var=$entry->summary|truncate:100}</i></p>
{/if}

{/foreach}
</div>
Called in a page with:

Code: Select all

{news summarytemplate='datetest'}
URL parameters to sort by month and year:

Code: Select all

?news_by_month=06-09