Page 2 of 3

Re: News Archives by Year/Month ( Tamplate + UDTs )

Posted: Tue Jul 20, 2010 1:45 pm
by Peciura
Actually if you need all new fields you could call News module detail action multiple times:

1. Create News detail template that looks like summary template;
2. Instead of {news_ids ids=$news_ids} do like this:

Code: Select all

{assign var='news_ids' value=','|explode:$news_ids}
{foreach from=$news_ids item='articleid'}
	{News action='detail' detailtemplate='summary' articleid=$articleid}
{/foreach}

Re: News Archives by Year/Month ( Tamplate + UDTs )

Posted: Tue Jul 20, 2010 2:30 pm
by nicmare
this is a pretty smart idea. but i need the summarization of a news article with its "more" link ;-).
next time i will use cgblog instead  :-\

Re: News Archives by Year/Month ( Tamplate + UDTs )

Posted: Tue Jul 20, 2010 3:57 pm
by Peciura
Well, that easy with SimpeSmarty

Code: Select all

{module_action_link module='News' action='detail' articleid=$articleid text='more...' page=$page}

Re: News Archives by Year/Month ( Tamplate + UDTs )

Posted: Tue Jul 20, 2010 8:35 pm
by nicmare
woho, did not have any experience with CGSS. is it possible to sort the multiple {news} in the foreach loop? for some reason they do not appear in the right order (i want them to sort by date).

Re: News Archives by Year/Month ( Tamplate + UDTs )

Posted: Tue Jul 20, 2010 11:52 pm
by Peciura
Updated {news_date} UDT now it takes parameters 'sort_by' and 'sort_order'. Available values are listed at the top of UDT.

Did not test it but think it should work.

Re: News Archives by Year/Month ( Tamplate + UDTs )

Posted: Wed Jul 21, 2010 6:55 am
by nicmare
thank you peciura.
but where to put this? i added it to

Code: Select all

{news_date  assign='news_ids' date="`$smarty.get.news_date`" sort_by="news_date"}
and also tried it in

Code: Select all

{news_ids ids=$news_ids sort_by="news_date"}
but it does not affect anything.

Re: News Archives by Year/Month ( Tamplate + UDTs )

Posted: Wed Jul 21, 2010 8:23 am
by Peciura
Try smth more obvious
{news_date  assign='news_ids' date="`$smarty.get.news_date`"  sort_by='news_title' sort_order='asc'}
I updated UDT  {news_date} once more just to make sure it is the latest one.

Only last {news_date} is important for displaying articles. Other just makes sure there are some articles of particular time span.

Re: News Archives by Year/Month ( Tamplate + UDTs )

Posted: Mon Jul 26, 2010 12:38 pm
by nicmare
well, this also dont work. cant manipulate the order :(

Re: News Archives by Year/Month ( Tamplate + UDTs )

Posted: Mon Jul 26, 2010 2:11 pm
by Peciura
I have just copied template and both UDTs from forum and it worked.

Update UDT 'news_date' once more.

Re: News Archives by Year/Month ( Tamplate + UDTs )

Posted: Mon Jul 26, 2010 2:41 pm
by nicmare
sorry mate, you are right! THANKS
one question left: how to leave inactive articles? it trys to display inactive articles too. so therefore i have two "more..." buttons.
and is it possible to wrap the more button around the {news} entry? because the "more" button isnt pretty nice.

Re: News Archives by Year/Month ( Tamplate + UDTs )

Posted: Mon Jul 26, 2010 3:21 pm
by Peciura
Updated both UDTs to include only 'published' articles.
More link is a simple link and created with smarty tag, so you can style it and move to News detail template as any other tag.
'more...' is an optional text, change value to one you like.
{module_action_link module='News' action='detail' articleid=$articleid text='more...' page=$page_alias}
EDIT: In News detail template it could look this way
{module_action_link module='News' action='detail' articleid=$articleid text=$mod->Lang('more') page=$page_alias}

Re: News Archives by Year/Month ( Tamplate + UDTs )

Posted: Mon Jul 26, 2010 3:55 pm
by nicmare
oh well,
i just take instead of module_action_link. this makes it possible to wrap the full article. this was a clients wish :-).
but now it works like expected. thank you very much! can't believe that we are the only ones, who need such a feature?! i mean, in my opinion this is essential for news module!

Re: News Archives by Year/Month ( Tamplate + UDTs )

Posted: Mon Jul 26, 2010 4:09 pm
by Peciura
It is possible most people are using it with old tags and with simple templates. So they are using UDT {news_ids} and do not need stuff related with News detail template.

Re: News Archives by Year/Month ( Tamplate + UDTs )

Posted: Fri Dec 17, 2010 12:40 pm
by nicmare
sorry peciura!
But i have one problem left.
the archive isnt ordered by date! i dont know why!
you see it here: http://www.smomkenya.org/news-archive
i tried to find the problem in  UDT "news_date":

Code: Select all

/*$params['assign']*//*mandatory*/
/*$params['date']*//*mandatory*//*9999-12-32 23:59:59*/
/* $params['sort_by']*//* create_date, modified_date, start_time, end_time, news_extra, news_id, news_title, news_date */
/* $params['sort_order'] */ /* ASC, DESC */
if (!empty($params['assign']) && !empty($params['date'])){

		$params['sort_by'] = trim(strtolower($params['sort_by']));
		switch ($params['sort_by']){
			case 'modified_date':
			case 'news_id':
			case 'news_title':
			case 'news_date':
			case 'start_time':
			case 'end_time':
			case 'news_extra':
			$sort_by = $params['sort_by'];
			break;
			default:
			$sort_by = 'create_date';
			break;
		}

		$params['sort_order'] = trim(strtoupper($params['sort_order']));
		switch ($params['sort_order']){
			case 'ASC' :
			$sort_order = $params['sort_order'];
			break;
			default:
			$sort_order = 'DESC';
			break;
		}

	$params['date'] = substr(trim($params['date']), 0, 19);
	$start_date = substr_replace('0000-00-00 00:00:00', $params['date'], 0, strlen($params['date']));
	$end_date = substr_replace('9999-12-31 23:59:59', $params['date'], 0,  strlen($params['date']));
	$assign = '';
	global $gCms;
	$db =& $gCms->GetDB();
	$query = 'SELECT news_id FROM '.cms_db_prefix()."module_news WHERE news_date >= ? AND news_date <= ? AND status = ? ORDER BY $sort_by $sort_order";
	$array = $db->GetArray($query,array($start_date, $end_date, 'published'));
	
	foreach($array as $row){
		$assign .= $row['news_id'].',';
	}
	$assign = rtrim($assign, ' ,');
	$smarty = $gCms->GetSmarty();
	$smarty->assign($params['assign'], $assign);
}
but i found nothing. whats wrong?

this is the GCB:

Code: Select all

{news_extreme_date assign=news_start_date extreme='min'}
{news_extreme_date assign=news_end_date extreme='max'}
{assign var='current_time' value='Y-m-d H:i:s'|date}
{assign var='active_year' value=$smarty.get.news_date|substr:0:4}

{assign var='start_year_list' value=$news_start_date|substr:0:4}
{assign var='loop_year_list' value=$news_end_date|substr:0:4}
<div class="newsarchivenavi">
{********** years ************}
<div class="newsarchivetitle">News in year:</div>
<ul class="newsbyyear">
{section name=year_list start=$start_year_list loop="`$loop_year_list+1`"}
<li>
   {news_date  assign='news_ids' date=`$smarty.section.year_list.index`}   {*coment if you want to see links to periods without articles*}
   {if !empty($news_ids)}            {*coment if you want to see links to periods without articles*}
      {capture assign=temp}?news_date={$smarty.section.year_list.index}{/capture}
      {if $smarty.section.year_list.index == $active_year}
         {$smarty.section.year_list.index}
      {else}
         {cms_selflink page=$page_alias urlparam=$temp text=$smarty.section.year_list.index}
      {/if}
   {/if}               {*coment if you want to see links to periods without articles*}
</li>
{/section}
</ul>

{********** years end*********}

{********** months and news *******************}
{assign var=mod value=$gCms->modules.FormBuilder.object}
{assign var='temp' value='date_january,date_february,date_march,date_april,date_may,date_june,date_july,date_august,date_september,date_october,date_november,date_december'}
{assign var='months' value=','|explode:$temp}
{if !empty($smarty.get.news_date)}
<ul class="newsbymonth clear">
   {********** months *************}
   {foreach from=$months name='months' item=month}

      {capture assign='news_date'}{$active_year}-{$smarty.foreach.months.iteration|string_format:"%'02u"}{/capture}

      {if ($news_date >= $news_start_date && $news_date <= $news_end_date) || (strpos($news_start_date, $news_date) !== FALSE) || (strpos($news_end_date, $news_date) !== FALSE)}
         {news_date  assign='news_ids' date="`$news_date`"}   {*coment if you want to see links to periods without articles*}
         {if !empty($news_ids)}            {*coment if you want to see links to periods without articles*}
<li>
            {capture assign='text'}{$mod->Lang($months[$smarty.foreach.months.index])}{/capture}
            {if $smarty.get.news_date!=$news_date}
               {cms_selflink page=$page_alias  text=$text urlparam="?news_date=$news_date"}
            {else}
               {$text}
            {/if}
</li>
         {/if}               {*coment if you want to see links to periods without articles*}
      {/if}

   {/foreach}
</ul>
{/if}
<div class="clear"></div>
</div>

<div class="newsarchive">
   {********** months end *********}
   {********** news ***************}

   {news_date  assign='news_ids' date="`$smarty.get.news_date`"  sort_by='create_date' sort_order='asc'}
   {if !empty($news_ids)}

      {*might be better option if you need all fields in articles *}
      {assign var='news_ids' value=','|explode:$news_ids}
      <div class="newssummary">
      {foreach from=$news_ids item='articleid'}
         <div class="newsitem clear{cycle values=' odd, even'}">
         {news action='detail' detailtemplate='summary' articleid=$articleid}
         </div>
      {/foreach}
      </div>
      {*news_ids ids=$news_ids*}
   {else}
      {assign var=mod value=$gCms->modules.News.object}
      {$mod->Lang('none')}            {*Visitor will this message if there is no articles for this period*}
   {/if}
   {********** news end ***********}
</div>

Re: News Archives by Year/Month ( Tamplate + UDTs )

Posted: Fri Feb 11, 2011 7:25 am
by allan1412
Filter News Articles by Category then apply Year Archive
Apologies for jumping in on this thread. I have applied this method and it works well - however I have several News Categories and was wondering how to filter the articles by category eg a separate page for each News Category which would have the Year Archive function.
Sorry if I'm missing the obvious solution.