If you paste template to empty(new) page you will see how it works. Using pretty urls or on defailt page should add "?" url parameter "&news_date=".
Also it is good idea not to cache page with all this stuff.
Template (page content) looks like this:
To build it you will need 3 UDTs and module FormBuilder (can be done without it):{*assign var='gCms' value=''|cmsms*} {*uncomment this line it template does not work with CMSms 1.8+ *}
{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}
{********** years ************}
{section name=year_list start=$start_year_list loop="`$loop_year_list+1`"}
{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*}
{/section}
{********** 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)}
{********** 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 Lang[/b]($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}
{/if} {*coment if you want to see links to periods without articles*}
{/if}
{/foreach}
{********** months end *********}
{********** news ***************}
{news_date assign='news_ids' date="`$smarty.get.news_date`" sort_by='create_date' sort_order='asc'}
{assign var=mod value=$gCms->modules.News.object}
{if !empty($news_ids)}
{*might be better option if you need all fields in articles *}
{assign var='news_ids' value=','|explode:$news_ids}
{foreach from=$news_ids item='articleid'}
{News action='detail' detailtemplate='summary' articleid=$articleid}
{module_action_link module='News' action='detail' articleid=$articleid text=$mod->Lang('more') page=$page_alias}
{/foreach}
{*news_ids ids=$news_ids*} {*original way for simple summaries*}
{else}
{$mod->Lang('none')} {*Visitor will this message if there is no articles for this period*}
{/if}
{********** news end ***********}
{/if}
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);
}
Code: Select all
/*$params['assign']*//*mandatory*/
/*$params['extreme']*//*mandatory*/ /* 'min' | 'max'*/
$extreme = strtoupper(trim($params['extreme']));
if (!empty($params['assign']) && ($extreme == 'MIN' or $extreme == 'MAX')){
$assign='';
global $gCms;
$db =& $gCms->GetDB();
$query = 'SELECT '.$extreme.'(news_date) FROM '.cms_db_prefix()."module_news ". " WHERE status = 'published'";
$assign = $db->GetOne($query);
$smarty = $gCms->GetSmarty();
$smarty->assign($params['assign'], $assign);
}
b. news_ids download attachment from this post http://forum.cmsmadesimple.org/index.ph ... #msg191719
This UDT takes majority of news module parameters - listed at the top of file.
You will need FormBuilder, because i used month names from this module. Months will be in the same language as page.
EDIT: Fixed template bug allowing to show all articles if none was valid for appropriate period. Now links to "empty" periods are not displayed, or you can choose to display message (e.g. "None")
EDIT: Added example with {News action='detail' ... } instead of UDT {news_ids}