next/previous pagination (UDT pagination)

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
baselve

next/previous pagination (UDT pagination)

Post 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.
Last edited by baselve on Mon Jan 22, 2007 3:31 pm, edited 1 time in total.
baselve

Re: next/previous pagination (UDT pagination)

Post 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?!
Jay7

Re: next/previous pagination (UDT pagination)

Post by Jay7 »

I am having this problem also. Any luck figuring it out?
baselve

Re: next/previous pagination (UDT pagination)

Post by baselve »

Not yet :( but I think it isn't very hard to fix for someone with a little bit talent for coding..
cyberman

Re: next/previous pagination (UDT pagination)

Post 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.
Last edited by cyberman on Thu Jan 25, 2007 5:36 am, edited 1 time in total.
baselve

Re: next/previous pagination (UDT pagination)

Post 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...
baselve

Re: next/previous pagination (UDT pagination)

Post 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...
cyberman

Re: next/previous pagination (UDT pagination)

Post 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/
baselve

Re: next/previous pagination (UDT pagination)

Post 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!
baselve

Re: next/previous pagination (UDT pagination)

Post 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!
Vin

Re: next/previous pagination (UDT pagination)

Post 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.
Last edited by Vin on Sun Feb 04, 2007 7:18 pm, edited 1 time in total.
icebrian
Forum Members
Forum Members
Posts: 24
Joined: Thu Dec 14, 2006 4:02 pm

Re: next/previous pagination (UDT pagination)

Post 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! :)
Last edited by icebrian on Thu Feb 08, 2007 5:03 pm, edited 1 time in total.
Locked

Return to “CMSMS Core”