Page 1 of 1

Show news by period without patching news module

Posted: Mon Jul 13, 2009 11:01 am
by blast2007
Considering difficulties to integrate period patch in news module, here a new version of news-by-period with vanilla news core files (no patch is needed).

Create a new template named as "summaryperiodtemplate" like this (minimal template):
{if !isset($news_start_period)}
   {assign var=news_start_period value='1900-01-01'}
{/if}

{if !isset($news_end_period)}
   {assign var=news_end_period value='2038-12-31'}
{/if}

{if isset($currentdate)}
   {assign var=news_start_period value=$currentdate}
{/if}


{foreach from=$items item=entry}
{if ($entry->postdate|date_format:'%F' >= $news_start_period|date_format:'%F') && ($entry->postdate|date_format:'%F' {$entry->postdate|date_format:"%d/%m/%Y"} - {$entry->title}
{eval var=$entry->content}
{/if}
{/foreach}


In red significative mods.

Then, if you want to show all year 2009 news, call news module in your page (or in your template) in this way:

Code: Select all

{* Select your news_start_date formatted as yyyy-mm-dd *}
{assign var='news_start_period' value='2009-01-01'}

{* Select your news_end_date formatted  as yyyy-mm-dd *}
{assign var='news_end_period' value='2009-12-31'}

{* Call news module *}
{news category="yourcategoryhere" summarytemplate="summaryperiodtemplate" detailtemplate="detailtemplate" }
Some other examples:

Here an example of page with 2009 month by month news collapsable:

Code: Select all

<ul>
<li>{startExpandCollapse id="January" title="January"}
{assign var='news_start_period' value='2009-01-01'}
{assign var='news_end_period' value='2009-01-31'}
{news category="yourcategoryhere" summarytemplate="summaryperiodtemplate" detailtemplate="detailtemplate" sortasc="true"}{stopExpandCollapse}
</li>
<li>{startExpandCollapse id="February" title="February"}
{assign var='news_start_period' value='2009-02-01'}
{assign var='news_end_period' value='2009-02-28'}
{news category="yourcategoryhere" summarytemplate="summaryperiodtemplate" detailtemplate="detailtemplate" sortasc="true"}{stopExpandCollapse}
</li>
...
</ul>

If you want next 5 upcoming news (starting from today) then proceed in this way:

Code: Select all

{* startdate is current date (today) *}
{capture assign='currentdate'}{current_date format="%F" }{/capture}

{* Call news module *}
{news category="yourcategoryhere" summarytemplate="summaryperiodtemplate" detailtemplate="detailtemplate" number="5"}
If you want to use news module without period feature, you can continue using the same template (summaryperiodtemplate) without setting any parameter.
I will update asap also my other news related post with this new feature
Waiting for your feedback

regards
blast

Re: Show news by period without patching news module

Posted: Mon Jul 27, 2009 10:35 pm
by Frankie
blast, this is EXCELLENT stuff...thanks for the great mod!  ;D

i am interested in 3 different variants of this mod without manually entering in the period params...

1. showing only news items from the last 30 days from current date
2. showing only news items from yesterday
3. showing only news items from today

any help would be great...thank you again for this post!

Re: Show news by period without patching news module

Posted: Tue Jul 28, 2009 11:23 pm
by blast2007
Franklin wrote: 1. showing only news items from the last 30 days from to(?) current date
create and UDT named getmyperiod with:

Code: Select all

global $gCms; 
$yesterday = date('Y-m-d',strtotime("-1 day"));
$last30day=date('Y-m-d',strtotime("-30 day"));
$smarty->assign(yesterday, $yesterday );
$smarty->assign(last30day, $last30day );
then in your page call

Code: Select all

{getmyperiod}
{capture assign="today"}{current_date|date_format:"%F"}{/capture}
{assign var='news_start_period' value='$last30day'}
{assign var='news_end_period' value='$today'}
{news summarytemplate='summarydatetest'}
Franklin wrote: 2. showing only news items from yesterday

Code: Select all

{getmyperiod}
{capture assign="today"}{current_date|date_format:"%F"}{/capture}
{assign var='news_start_period' value='$yesterday'}
{assign var='news_end_period' value='$today'}
{news summarytemplate='summarydatetest'}
Franklin wrote: 3. showing only news items from today

Code: Select all

{capture assign="today"}{current_date|date_format:"%F"}{/capture}
{getmyperiod}
{assign var='news_start_period' value='$today'}
{assign var='news_end_period' value='$today'}
{news summarytemplate='summarydatetest'}
regards
blast

Re: Show news by period without patching news module

Posted: Wed Jul 29, 2009 1:54 pm
by Frankie
wow, thanks blast! kudos!  ;D

Re: Show news by period without patching news module

Posted: Thu Sep 24, 2009 7:07 am
by moonie
Blast, this is a fantastic news template and works like a charm!

I have one single question that I can't figure out on my own... I am using the month by month example and would like to check if lets say, there are news for the month of September, and only output the collapse/month name if there are.

Any help would be greatly appreciated!

Re: Show news by period without patching news module

Posted: Thu Sep 24, 2009 6:21 pm
by blast2007
moonie wrote: . I am using the month by month example and would like to check if lets say, there are news for the month of September, and only output the collapse/month name if there are.

Any help would be greatly appreciated!
moonie,
you could use "capture" to check if there is an empty month...
something like: (to be tested)
...
{assign var='news_start_period' value='2009-01-01'}
{assign var='news_end_period' value='2009-01-31'}
{capture assign="currentmonth"}{news category="yourcategoryhere" summarytemplate="summaryperiodtemplate" detailtemplate="detailtemplate" sortasc="true"}{/capture}
{if !empty($checkmonth)}
{startExpandCollapse id="January" title="January"}
{$currentmonth}

{stopExpandCollapse}
{/if}
...
As said before I haven't still test this code so I don't know if it works (It should...;) )

regards
blast

Re: Show news by period without patching news module

Posted: Sat Sep 26, 2009 9:20 am
by moonie
Hello blast,

the {if !empty} part doesn't quite want to work in that example, but I'll try to figure it out on my own, thanks for the direction  :)

Re: Show news by period without patching news module

Posted: Fri Oct 02, 2009 5:14 pm
by NikNak
Hi - this all works really well, as all the news pages I have ever done on sites have a year submenu.

What I'm wondering is how you could make these into links that could effect the main news module, rather than creating a new page for each period. So clicking on a link for '2009' would not open a new page but would refresh the current page with the relevant data.

It would be nice to have this incorporated into the news module - hopefully one day.

Thanks Blast

Nik

Re: Show news by period without patching news module

Posted: Mon Mar 08, 2010 4:41 pm
by mox
moonie wrote: Hello blast,

the {if !empty} part doesn't quite want to work in that example, but I'll try to figure it out on my own, thanks for the direction  :)
Please, can you tell me about your solution?
Thx
Mox

Re: Show news by period without patching news module

Posted: Tue Mar 09, 2010 7:38 am
by Gregor
This is a great extension to the news module!

Give the user a feature and they ask for more ;) Is there a way that I can create a dropdown box or so, so that the visitor can select a year that they would like to see the news of?

Gregor

Re: Show news by period without patching news module

Posted: Mon Mar 15, 2010 4:20 pm
by gap_tooth_clan
I had a design that has a view news articles by month page and links to navigate from month to month. I spent a couple of hours scratching my head and came up with this.

make a UDT with the name getNewsRange

Code: Select all

 if( isset( $params['to'] ) )
  {
    global $gCms;
    $manager =& $gCms->GetHierarchyManager();
    $node =& $manager->sureGetNodeByAlias($params['to']);
    $content =& $node->GetContent();
    if (isset($content) && is_object($content))
       {
         if ($content->GetURL() != '')
         {
            $url = $content->GetURL();
			
			if (isset($_GET['month']) && $_GET['month'] < 13 && $_GET['month'] > 0 &&
			isset($_GET['year']) && $_GET['year'] < 2035 && $_GET['year'] > 2000) {
			
				$year = $_GET['year'];
				$month= $_GET['month'];
			
			} else {
			
				$year = date("Y");
				$month = date("m");
			
			}
			
			// make new date a month in advance
			
			if ($month == 12) {
				$monthAdvance = 1;
				$yearAdvance = $year + 1;
			} else {
				$monthAdvance =  $month + 1;
				$yearAdvance = $year;
			}
			
			// make new date a month in reverse
			
			if ($month == 1) {
				$monthReverse = 12;
				$yearReverse = $year - 1;
			} else {
				$monthReverse =  $month - 1;
				$yearReverse = $year;
			}
			
			
			$monthName = date("F", mktime(0, 0, 0, $month, 10)); 
			
			
			
			$smarty->assign('newsStartRange', $year . '-' . $month);
			$smarty->assign('newsEndRange', $yearAdvance . '-' . $monthAdvance);
			
			$smarty->assign('newsPrevMonth', '<a href="' . $url . '?year=' . $yearReverse . '&month=' . $monthReverse . '">Previous</a>');
			$smarty->assign('newsNextMonth', '<a href="' . $url . '?year=' . $yearAdvance . '&month=' . $monthAdvance . '">Next</a>');
			
			$smarty->assign('newsMonthName', $monthName);			
			

         }
       }
    else return '<!-- destination page was not found: '.$params['to'].' -->';
  }
Now call your news template like so: nb latest-news is my page where my news tag is

Code: Select all

{getNewsRange to='latest-news'}

{$newsPrevMonth}
{$newsMonthName}
{$newsNextMonth}
<div>{* Select your news_start_date formatted as yyyy-mm-dd *}
{assign var='news_start_period' value=$newsStartRange}

{* Select your news_end_date formatted  as yyyy-mm-dd *}
{assign var='news_end_period' value=$newsEndRange}

{* Call news module *}
{news summarytemplate="summaryperiodtemplate" detailtemplate="detailtemplate" }</div>
Used a bit of code from calguys redirect to get the Url, which is why you have to pass in the parameter, does anyone know a more elegant solution?

Re: Show news by period without patching news module

Posted: Mon Mar 15, 2010 4:25 pm
by Gregor
Thanks for dropping your code and thoughts. Will give it a try.

Gregor

Re: Show news by period without patching news module

Posted: Sun May 16, 2010 1:05 am
by CMSmonkey
Hello,
I am using News 2.10.4 and CMSMS 1.6.7 and trying to use the recommendation blast2007 has above to show only news articles between a certain time period.

I created 3 test entries:
1 that runs from April 1 - April 23, 2010
1 that runs from February 15 - May 30, 2010
1 that never expires

I inserted the template "summaryperiodtemplate" into the News module's summary template section.

I then entered the following into my page's content:

Code: Select all

{* Select your news_start_date formatted as yyyy-mm-dd *}
{assign var='news_start_period' value='2010-01-01'}

{* Select your news_end_date formatted  as yyyy-mm-dd *}
{assign var='news_end_period' value='2010-04-30'}

{* Call news module *}
{news summarytemplate="summaryperiodtemplate"}
However, it does not display anything.  If I change the end date to 2010-05-30, then the entry that never expires and the entry that ends May 30th are shown.  Does this method not show expired news articles?  Is this even the issue or is there something I am doing wrong?

Any help is appreciated.  Thanks.

Re: Show news by period without patching news module

Posted: Tue May 18, 2010 11:03 am
by blast2007
Following my previous post, here some hints to add an RSS feed to your filtered news.
Required module: Calguys Feed Maker

Create a new feed in Calguys Feed Maker (i.e. filtered-news) filling required fields. In your standard template modify the bottom part starting with:

Code: Select all

  {* an example of how to create a feed from a call to the news module *}
    {* you can use any smarty variable that is available in the news summary template *}
    {* you can substitute this logic with output from any module that supports a summary
       view, or possibly get artistic and mix output from different modules *}
    {news assign='junk'}
    {foreach from=$items item='entry'}
    <item>
      <title>{$entry->title|cms_html_entity_decode}</title>
      <link>{$entry->moreurl}</link>
      {capture assign='description'}{if isset($entry->summary)}{$entry->summary}{else}{$entry->content}{/if}{/capture}
      <description>{$description|trim|summarize:40}</description>
      <pubDate>{$entry->postdate|rfc_date}</pubDate>
      <guid>{$entry->moreurl}</guid>
    </item>
    {/foreach}
  </channel>
</rss>
with this code:

Code: Select all

    {capture assign='currentdate'}{current_date format="%F" }{/capture}
    {assign var=num value=5}
    {news assign='junk' category='yourcategoryhere' sortasc="true"}
    {foreach from=$items item='entry'}
    {if ( $entry->postdate|date_format:'%F' >= $currentdate) && $num>0}
    {assign var=num value=$num-1}
    <item>
      <title>{$entry->title|cms_html_entity_decode}</title>
      <link>{$entry->moreurl}</link>
      {capture assign='description'}{eval var=$entry->content}{/capture}
      <description>{$description|trim|strip_tags|summarize:40}</description>
      <pubDate>{$entry->postdate|rfc_date}</pubDate>
      <guid>{$entry->moreurl}</guid>
    </item>
    {/if}
    {/foreach}
  </channel>
</rss>
regards
blast