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?
News Module and an archive like section
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
- Location: Fernie British Columbia, Canada
Re: News Module and an archive like section
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).
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).
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Re: News Module and an archive like section
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):
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
after the loop.
On the news page itself, I have the following:
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.
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);
Code: Select all
$numitems=0;
Code: Select all
$numitems++;
Code: Select all
$this->$smarty->assign_by_ref('numitems',$numitems);
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>
Unfortunately you can't see this in action as it is only running in a test environment at the moment.
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
- Location: Fernie British Columbia, Canada
Re: News Module and an archive like section
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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Re: News Module and an archive like section
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
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 addingbefore the loop,Code: Select all
$numitems=0;
inside the loop, andCode: Select all
$numitems++;
after the loop.Code: Select all
$this->$smarty->assign_by_ref('numitems',$numitems);
Re: News Module and an archive like section
I get an error on this syntax: $this->$smarty->assign_by_ref('numitems',$numitems);