News Module and an archive like section

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
Safrax

News Module and an archive like section

Post 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?
calguy1000
Support Guru
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

Post 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).
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.
Matthew Bemand

Re: News Module and an archive like section

Post 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

Code: Select all

$numitems=0;
before the loop,

Code: Select all

$numitems++;
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.
calguy1000
Support Guru
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

Post 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.
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.
mox
Forum Members
Forum Members
Posts: 113
Joined: Wed Feb 08, 2006 2:32 pm

Re: News Module and an archive like section

Post 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

Code: Select all

$numitems=0;
before the loop,

Code: Select all

$numitems++;
inside the loop, and

Code: Select all

$this->$smarty->assign_by_ref('numitems',$numitems);
after the loop.
baselve

Re: News Module and an archive like section

Post by baselve »

I get an error on this syntax: $this->$smarty->assign_by_ref('numitems',$numitems);
Locked

Return to “Modules/Add-Ons”