Note de ce sujet :
  • Moyenne : 0 (0 vote(s))
  • 1
  • 2
  • 3
  • 4
  • 5

Archives du module News
#6

Bonjour,

Je cherche aussi à archiver mes articles. J'ai trouvé une réponse sur le forum en anglais (http://forum.cmsmadesimple.org/viewtopic.php?t=42601)

Il faut :

1) Créer un page sur laquelle on veut afficher les news, désactiver le wysiwyg et coller ceci :

Code :
{*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 <= $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*}
{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}
{/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}

2) Créer une balise utilisateur news_date et coller ceci :

Code :
/*$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);
}

3) Créer une balise utilisateur news_extreme_date et coller ceci :

Code :
/*$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);
}


Le résultat attendu : http://www.alytausmuziejus.lt/naujienos-12/lt

Mon résultat : http://www.unssf.org/aaa

Je parviens à afficher les années et les mois contenant des news avec les liens "En savoir plus" qui pointent vers les articles mais je n'arrive pas à afficher le résumé de ces articles.

Quelqu'un peut-il me donner un coup de main ?

CMSMS 1.6
90plan OVH
Répondre


Messages dans ce sujet

Atteindre :


Utilisateur(s) parcourant ce sujet : 2 visiteur(s)