I was in the need for a archive function as described in this post. With a different approch i got it working without any modifications of the news module.
Insted I use the fact that you can filter what news that are displayed based on post id.
I used the default news summary function to provide the month/year list like this:
2010
• November (9)
• December (16)
2011
• January (2)
It is created with the following news summary template:
Code: Select all
<!-- Start Categorylist -->
{foreach from=$cats item=node}
{if $node.count > 0}<a href="/news-archive/?category={$node.news_category_name}">{$node.news_category_name}</a>
{else}<span>{$node.news_category_name}</span>{/if}
{/foreach}
<hr/>
<!-- Start News Archive -->
<ul class="list2">
{assign var="month_count" value=0}
{assign var="post_count" value=0}
{assign var="startpost" value=0}
{foreach from=$items item=entry}
{if $entry->postdate}
{assign var="post_year" value=$entry->postdate|date_format:"%Y"}
{assign var="post_month" value=$entry->postdate|date_format:"%m"}
{if $post_month != $lastpost_month && $lastpost_month}
<li>
<a href="{cms_selflink href='news-archive'}?startpost={$startpost}&numposts={$month_count}&pagetitle={$lastpost_monthname}-{$lastpost_year}">
{$lastpost_monthname}</a> ({$month_count})</li>
{assign var="month_count" value=1}
{assign var="startpost" value=$post_count}
{else}
{math equation="x + 1" x=$month_count assign="month_count"}
{/if}
{if $post_year != $lastpost_year && $lastpost_year}</ul></li>{/if}
{if $post_year != $lastpost_year}
<li>{$post_year}<ul>
{/if}
{assign var="lastpost_year" value=$post_year}
{assign var="lastpost_month" value=$post_month}
{assign var="lastpost_monthname" value=$entry->postdate|date_format:"%B"}
{math equation="x + 1" x=$post_count assign="post_count"}
{/if}
{/foreach}
<li>
<a href="{cms_selflink href='news-archive'}?startpost={$startpost}&numposts={$month_count}&pagetitle={$lastpost_monthname}-{$lastpost_year}">
{$lastpost_monthname}</a> ({$month_count})</li>
</ul></li></ul>
<!-- End News Archive -->
To display the correct news it is requred to have a page with alias
news-archive . In this page, disable WYSIWYG and paste the folowing code:
Code: Select all
{news_archive_setup}
<h1>{$pagetitle}</h1>
{if $category}{news category=$category}
{else}{news start=$startpost pagelimit=$numposts}
{/if}
And finaly add a UDT called
news_archive_setup:
Code: Select all
global $gCms;
global $smarty;
if (isset($_GET['category']) || $_GET['category'] != "") {
$category=$_GET['category'];
$smarty->assign('category', $category);
}
if (!isset($_GET['startpost']) || $_GET['startpost'] == "") {
$startpost=0;
} else {
$startpost=$_GET['startpost'];
}
if (!isset($_GET['numposts']) || $_GET['numposts'] == "") {
$numposts=20;
} else {
$numposts=$_GET['numposts'];
}
if (isset($_GET['pagetitle']) || $_GET['pagetitle'] != "") {
$pagetitle= htmlentities("Newsarchive - ".$_GET['pagetitle']);
} elseif (isset($_GET['category']) || $_GET['category'] != "") {
$pagetitle= htmlentities("Newsarchive - ".$_GET['category']);
} else {
$pagetitle="Newsarchive";
}
$smarty->assign('startpost', $startpost);
$smarty->assign('numposts', $numposts);
$smarty->assign('pagetitle', $pagetitle);