The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
[HOW TO - vB4] Paginating Results
Introduction Not very much has changed regarding how pagination works since vB 3.8, but quite enough to warrant an update of Revan's great tutorial, dating from 2006. Kudos to Revan. As Revan I assume you know your way around php and can understand at least roughfly what each bit of the code does. There'll be explanations, of course, but this is for coders and mod developers. The main work for pagination has to be done in the PHP-code, still no surprise there. Cleaning URL parameters We start off by cleaning the URL parameters that will tell our paginator how many entries to show per page and on which page of the resultset we're actually on PHP Code:
Counting results The next step is to count the number of resuts that our actual database query will return (this query we will meet later on - it's an example that will throw all users with no posts). PHP Code:
Settings & sanitizing Next we're off to do some settings: The first argument is our counting result. The last two arguments are the maximum number of results per page (100) and the default number of results per page (20). Note how the first argument is the result of the count query above. You can replace those with settings from the AdminCP by inserting the corresponding variables obviously. PHP Code:
Orientation - where are we? Now some stuff to determine on which page we're on and which results to show. Note how you have to provide the results of our initial count query: PHP Code:
The main query Now the query that throws all users with no posts - just an example, obviously. Note the LIMIT - this has to be added to the original query to delimit the resultset for the actual page PHP Code:
Constructing pagenav The last (but one) thing to do in the PHP code is to finally call the function to construct the actual page-nav and saving it's output to a variable for passing to the template.
PHP Code:
Registering pagenav for templates As with all variables in vB4, the newly created $pagenav has to be registered to be used inside the template: PHP Code:
Template code Now you just have to put the pagenav-code into your template, and we're done. Note that the id of the surrounding div should be changed to "pagination_bottom" or "pagination_top" accordingly. Code:
<vb:if condition="$pagenav"> <div id="pagination_top"> {vb:raw pagenav} </div> </vb:if> -c As of now (beta 3), there are still some issues that need to be resolved regarding pagination. They are minor and there should not be substantial changes, but be aware of that. For example, the setting of results shown per page does not work yet - 20 is hardcoded into the sanitizing function. |
#22
|
|||
|
|||
Hello,
Any idea why this method even working fine in other (custom) pages, does not works in member.php? I've added a custom tab there (thank you again as that aricle is also yours), I used the same code that I had in my php file (copy & paste), but even if the navbar appears, it has:
Thank you C.T. |
#23
|
|||
|
|||
Just to post a followup. Finally I was able to find what causes the error, but now it left the harder, on how to solve it.
vBulletin when constructs a page adds page=xx at the end of link. The problem is when the link contains &tab=mytab#selectedtab. In this case seems that vB ignores anything after &tab=mytab#selectedtab, so it can't get the inbound page nbr. I tried placing &page=2 before &tab=mytab#selectedtab, and it works fine. Now I need to find a way to get the actual pagenumber to set it there as variable. $pagenumber does not works as it shows the same page. C.T. |
#24
|
||||
|
||||
When you construct the link, you can pass an anchor. The selected tab should be present as a variable ($selected_tab?), and since the anchor is always the same as the id, you should be able to completely construct the URL needed.
|
#25
|
|||
|
|||
Quote:
Code:
$pagenav = construct_page_nav($pagenumber, $perpage, $records, 'member.php?' . $vbulletin->session->vars['sessionurl'] . 'u='.$userid.'&action=1&tab=classifieds#classifieds'); Code:
$pagenav = construct_page_nav($pagenumber, $perpage, $records, 'member.php?' . $vbulletin->session->vars['sessionurl'] . 'u='.$userid.'&action=1', '&tab=classifieds#classifieds'); |
#26
|
|||
|
|||
Hello everyone, quick question;
What about multiple pagination instances on the same template for example? I am having a bit of trouble with the second and third instances. I created 3 separate files and inserted them into the same template as plugins. Using three instances of: HTML Code:
<vb:if condition="$pagenav"> <div id="pagination_top"> {vb:raw pagenav} </div> </vb:if> HTML Code:
<div id="test" class="block collapse"> <div class="blocksubhead">My First Place Trophies ({vb:raw oftw_firstplace_times})<a class="collapse" id="collapse_cel_dummy" href="{vb:raw relpath}#top" style="top: 5px;"><img src="{vb:stylevar imgdir_button}/collapse{vb:raw vbcollapse.collapseimg_cel_dummy_img}_40b.png" /></a></div> <div class="blockrow" id="cel_dummy"> <center>{vb:raw oftw_get_mytrophies}</center> <vb:if condition="$pagenav1"> <div id="pagination_top1" style="float: right; margin-bottom: 27px; margin-right: 5px;"> <center>{vb:raw pagenav1}</center> </div> </vb:if> </div> </div> <div id="test" class="block collapse"> <div class="blocksubhead">My Second Place Trophies ({vb:raw oftw_secplace_times})<a class="collapse" id="collapse_cel_dummy2" href="{vb:raw relpath}#top" style="top: 5px;"><img src="{vb:stylevar imgdir_button}/collapse{vb:raw vbcollapse.collapseimg_cel_dummy_img}_40b.png" /></a></div> <div class="blockrow" id="cel_dummy2"> <center>{vb:raw oftw_get_mysectrophies}</center> <vb:if condition="$pagenav2"> <div id="pagination_top2" style="float: right; margin-bottom: 27px; margin-right: 5px;"> <center>{vb:raw pagenav2}</center> </div> </vb:if> </div> <div id="test" class="block collapse"> <div class="blocksubhead">My Third Place Trophies ({vb:raw oftw_thirdplace_times})<a class="collapse" id="collapse_cel_dummy3" href="{vb:raw relpath}#top" style="top: 5px;"><img src="{vb:stylevar imgdir_button}/collapse{vb:raw vbcollapse.collapseimg_cel_dummy_img}_40b.png" /></a></div> <div class="blockrow" id="cel_dummy3"> <center>{vb:raw oftw_get_mythirdtrophies}</center> <vb:if condition="$pagenav3"> <div id="pagination_top3" style="float: right; margin-bottom: 27px; margin-right: 5px;"> <center>{vb:raw pagenav3}</center> </div> </vb:if> </div> |
#27
|
||||
|
||||
As far as I can see, the vB pagination classes won't work for multible instances per page. For what you seem to be after, I'd use some nifty jQuery AJAX thingy, to be honest, to get around all the page reloads the php method causes.
|
#28
|
|||
|
|||
Ahh , thanks Cellarius, I have been looking at some jquery pagination already but would have rather used vb built it mechanisms, oh well. I'll post here when I find something to share with everyone. Thanks for the feedback cel.
|
#29
|
||||
|
||||
I run my script like this myscript.php? id = $ id how I could add
PHP Code:
how to add $ id in this part of code: PHP Code:
|
#30
|
||||
|
||||
Glad I found this article... Still something new to learn.
|
#31
|
|||
|
|||
trying to implement this on an admin page.
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|