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

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
ljonizuka

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

Post 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
Jeff
Power Poster
Power Poster
Posts: 961
Joined: Mon Jan 21, 2008 5:51 pm
Location: MI

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

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

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

Post 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?
Jeff
Power Poster
Power Poster
Posts: 961
Joined: Mon Jan 21, 2008 5:51 pm
Location: MI

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

Post by Jeff »

Try putting {$entry->postdate|date_format:'%m'} or {$entry->postdate} in your template to see what they are outputting/they equal.
ljonizuka

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

Post 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.
ljonizuka

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

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

Return to “The Lounge”