Page 1 of 1

next/previous pagination (UDT pagination)

Posted: Mon Jan 22, 2007 1:38 pm
by baselve
Hi there,

I've implemented the pagination in my news module (annex blog) like written in the handbook here:
http://wiki.cmsmadesimple.org/index.php ... fined_Tags

Code: Select all

{newsindex number='5' start='0'}  
{cms_module module='news' number=$news_number start=$news_start}
<a href="{$news_prev_url}">Previous</a>
<a href="{$news_next_url}">Next</a>
I use the code above for showing my older news and the previous link to go back to newer news. Although there's one problem... The next and previous links are there all the time, even when there's no page with older news or newer news (blank page shows up). I'm looking for something that in case there's no older news left the "next" link won't show up (similar for the previous link when you're on page 1 of the news).

I think it must be possible with if statements but I have no idea how to make it work in combination with pagination UDT from the CMSMS handbook. With the search I found the code below and as far I can see/understand is that what I need. Unfortunately I'm a very bad coder, so my question is: is it possible to do something similar for the UDT pagination from the handbook???

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>
http://forum.cmsmadesimple.org/index.ph ... 109.0.html

Many thanks in advance, it's one of the last things I need to do to complete my blog based on CMSMS and the newsmodule.

Re: next/previous pagination (UDT pagination)

Posted: Wed Jan 24, 2007 1:20 pm
by baselve
is there no php-guru in the house to solve this problem??? I mean.... it must be a general problem for more people that use the pagination UDT from the wiki/handbook?!

Re: next/previous pagination (UDT pagination)

Posted: Wed Jan 24, 2007 9:16 pm
by Jay7
I am having this problem also. Any luck figuring it out?

Re: next/previous pagination (UDT pagination)

Posted: Wed Jan 24, 2007 9:18 pm
by baselve
Not yet :( but I think it isn't very hard to fix for someone with a little bit talent for coding..

Re: next/previous pagination (UDT pagination)

Posted: Thu Jan 25, 2007 5:24 am
by cyberman
Haven't tried the wiki solution ... but have you seen this thread?

http://forum.cmsmadesimple.org/index.ph ... 873.0.html

I know it's in italian but think you can read the posted sources  ;) ... or translate it with google.

Maybe it helps.

Re: next/previous pagination (UDT pagination)

Posted: Thu Jan 25, 2007 2:38 pm
by baselve
cyberman wrote: Haven't tried the wiki solution ... but have you seen this thread?

http://forum.cmsmadesimple.org/index.ph ... 873.0.html
Unfortunately, it gives a direct error...

Re: next/previous pagination (UDT pagination)

Posted: Thu Jan 25, 2007 5:51 pm
by baselve
If there's any way to "count" the news items then I think we are one step closer to solve this problem. When you know the number of newsitems you can make a if-statement for when to show next/previous. I experimented something with countrow, but no succes so far....

I must confess I'm a little bit frustrated about this, thanks to CMSMS I made a great blog, but perfection isn't possible when I don't fix this problem... :( Besides, I really think this must be a general problem for many users who use news as a blog system...

Re: next/previous pagination (UDT pagination)

Posted: Fri Jan 26, 2007 5:22 am
by cyberman
There's another way havent't tried yet. There's a smarty plugin which should do that

http://www.phpinsider.com/php/code/SmartyPaginate/

Re: next/previous pagination (UDT pagination)

Posted: Fri Jan 26, 2007 10:45 am
by baselve
Thank you, I'll give it a try and read the documentation carefully. I'm more a designer than a coder so it will be very hard I think!

Re: next/previous pagination (UDT pagination)

Posted: Sat Jan 27, 2007 6:56 pm
by baselve
I was not very succesful with the smarty plugin, but I'm one step closer :)

I made a UDT that reads the numer of news articles:

Code: Select all

global $gCms;

$db = &$gCms->db;

$sql = "SELECT COUNT(news_id) FROM cms_module_news";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$numOfArticles = $row['COUNT(news_id)'];
return $numOfArticles;


echo $numOfArticles;
next step is to divide the numer of articles by the number of articles shown per page so "the system" knows how many pages it must show!

Re: next/previous pagination (UDT pagination)

Posted: Sun Feb 04, 2007 3:41 pm
by Vin
next step is to divide the numer of articles by the number of articles shown per page so "the system" knows how many pages it must show!
--------------------------------------------------------------------
Why,

Code: Select all

{if $news_start + $news_number < $numOfArticles}<a href="{$news_next_url}">Older news</a>{/if}
will suffice, won't it? ($numOfArticles has to be inserted into smarty, 'course).

The division of the $numOfArticles could be used for 1 | 2| 3 | ....| 9 list, though... I will look into it further.

Nevertheless, it's pretty primitive; and I would like to know if the MySQL query which is used doesn't slow the CMS too much.

THX for inspiration, anyway. I'm a neophyte to php.

Re: next/previous pagination (UDT pagination)

Posted: Thu Feb 08, 2007 4:56 pm
by icebrian
All working...

UDT code:

Code: Select all

global $gCms;

$start = ($_REQUEST['start']) ? $_REQUEST['start'] : $params['start'];
$number = ($_REQUEST['number']) ? $_REQUEST['number'] : $params['number'];

$next_uri = 'index.php?page=' . $gCms->variables['page_name'] . '&start=' . ($start + $number) . '&number=' . $number;
$prev_uri = 'index.php?page=' . $gCms->variables['page_name'] . '&start=' . ($start - $number) . '&number=' . $number;

$db = &$gCms->db;
$sql = "SELECT COUNT(news_id) FROM cms_module_news";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$numOfArticles = $row['COUNT(news_id)'];

$smarty->assign('news_start', $start);
$smarty->assign('news_number', $number);
$smarty->assign('news_next_url', $next_uri);
$smarty->assign('news_prev_url', $prev_uri);
$smarty->assign('news_numb_articles', $numOfArticles);
And for the page itself:

Code: Select all

{newsindex number='10' start='0'}
{cms_module module='news' number=$news_number start=$news_start}
{if $news_start > '0'}<a href="{$news_prev_url}">Back</a>{/if}
{if $news_start + $news_number < $news_numb_articles}<a href="{$news_next_url}">Next</a>{/if}
Thanks everyone! :)