Page 1 of 1
News Module and an archive like section
Posted: Wed Feb 08, 2006 3:57 pm
by Safrax
First off thanks for making CMSMS not suck. It's the best CMS I've used so far even if it is a bit rough around the edges.
On the news section of my website I want some kind of link to display older news items like an archive section but split up into pages with say 5 articles per page. Is there a way to do this currently or does such functionality not exist?
Re: News Module and an archive like section
Posted: Wed Feb 08, 2006 5:17 pm
by calguy1000
Well, sort of..... there's no pagination stuff built in to the front end tags yet
but you can use two news tags, and use the "start" and "number" parameters to control how many, and which articles get displayed. (as of 0.12b1 at least).
Re: News Module and an archive like section
Posted: Sun Feb 19, 2006 6:05 pm
by Matthew Bemand
I've managed to achieve something like this, though I've only managed 'next' and 'previous' links rather than links to each page.
First of all I created a user-defined tag called getstartnum to get a start number from the query string and defaulting to 0 (i.e. the first item):
Code: Select all
if(isset($_GET["start"]))
{
$startnum=$_GET["start"];
}
else
{
$startnum= 0;
}
$smarty->assign('startnum', $startnum);
$smarty->assign('nextpagestart', $startnum+10);
$smarty->assign('prevpagestart', $startnum-10);
$smarty->assign('pagenum', ($startnum+10)/10);
I then tweaked the news module a bit to tell me how many news items are being displayed: This involved finding the bit of the module that looped through the query to get each item, and adding
before the loop,
inside the loop, and
Code: Select all
$this->$smarty->assign_by_ref('numitems',$numitems);
after the loop.
On the news page itself, I have the following:
Code: Select all
<p>{getstartnum}
{cms_module module='news' start=$startnum number='10' category='news,articles' moretext='More...'}
{if $numitems==0}No news or articles to display.{/if}</p>
<p>{if $pagenum!=1}
<a href="index.php?page=News_Articles&start={$prevpagestart}">«Prev</a> {/if}
{if $pagenum!=1 || $numitems==10} Page {$pagenum} {/if}
{if $numitems==10}<a href="index.php?page=News_Articles&start=$nextpagestart}">Next»</a>{/if}</p>
This gives me a 'prev' link on every page but the first, a page number if there is more than one page, and a 'next' link if it looks like there is going to be another page. If the number of news items is a multiple of 10 then the final page will have a link to a blank page, but actually checking if there is any more after this page looked like it was going to get complicated.
Unfortunately you can't see this in action as it is only running in a test environment at the moment.
Re: News Module and an archive like section
Posted: Sun Feb 19, 2006 6:33 pm
by calguy1000
excellent, I would recommend you update to the latest svn (again if necessary) and create a patch, then submit that to the forum, I think that would be included with little problem.
Re: News Module and an archive like section
Posted: Wed Mar 08, 2006 1:44 pm
by mox
Hi Matthew,
it's almost clear, but I don't find the loop in the News.module.php;
you would know to say where I can find it?
Thanks
mox
I then tweaked the news module a bit to tell me how many news items are being displayed: This involved finding the bit of the module that looped through the query to get each item, and adding
before the loop,
inside the loop, and
Code: Select all
$this->$smarty->assign_by_ref('numitems',$numitems);
after the loop.
Re: News Module and an archive like section
Posted: Thu Jan 25, 2007 3:07 pm
by baselve
I get an error on this syntax: $this->$smarty->assign_by_ref('numitems',$numitems);