Customizing SMF > SMF Coding Discussion
How do I paginate an SSI function?
(1/1)
Liam_michael:
Using SSI_Recenttopics(25) for instance, if I'm displayed 25 topics, how do I add pagination so that the user can view the next 25 topics?
http://biology-forums.com/index.php?action=unanswered
Here's an example where I display 50+ topics. I'd like the ability to have a page index at the bottom that shows that next 25.
Could someone look into this for me? Has anyone done this before?
Suki:
There is 2 ways, one is to mess up the query, is the best solution but is messy. The other one is using a pagination based on an array, it's slower specially if you have big, big arrays but it is easy to implement because you don't mess with your existing code.
I have a class for pagination: https://github.com/MissAllSunday/Common-Classes OharaPagination.php with this you only need to iniciatr a new pagination instance:
$pagination = new OharaPagination($array, $page, '?page=', '', 5, 5);
the parameters are:
$array the whole array (the 50 messages)
$page is the number of the page you are on, leave it at 1, later the class will figure this out
$url suffix in this cas we will append the page var on the url
$url prefix not necesarry but you can append something to the beginning of the url
5 number of pages to show, if you want 2 pages, then put 2 the class will automatically fragment your array based on that.
5 the number of pages to display in the pagination number div, ie 1,2,3,4,5,etc
Now you can display your pagination with this:
$pagination->paginationArray(); call this to generate the data
this is the actual data: $pagination->outputArray();
this is the pagination numbers $pagination->outputPanel();
put this whereever you want the data and the numbers to appear.
Liam_michael:
Thanks for your detailed response, I'll read through it and respond back if I need more assistance.
Navigation
[0] Message Index
Go to full version