View previous topic :: View next topic |
Author |
Message |
GamerZ
Joined: 15 May 2002 Posts: 537 Location: Singapore
|
Posted: Sun Jan 05, 2003 4:37 pm Post subject: [Hacks] Vbulletin Style Page Numbers |
|
|
I have created a function to have vbulletin style page numbering like Pages (9): [1] 2 3 4 5 » ... Last »
Open up b2template.functions.php add in this function[php:1:40d3d09621]function pagenavi($prelabel='<< Previous Page', $nxtlabel='Next Page >>') {
global $p, $what_to_show, $request, $posts_per_page;
global $HTTP_SERVER_VARS, $siteurl, $blogfilename, $paged;
global $querystring_start, $querystring_equal, $querystring_separator;
if (empty($p) && ($what_to_show == 'paged')) {
$nxt_request = $request;
$whichpage = $_GET['paged'];
if(empty($whichpage)) $whichpage = 1;
$qstr = $HTTP_SERVER_VARS['QUERY_STRING'];
if (!empty($qstr)) {
$qstr = preg_replace("/&paged=\d{0,}/","",$qstr);
$qstr = preg_replace("/paged=\d{0,}/","",$qstr);
} elseif (stristr($HTTP_SERVER_VARS['REQUEST_URI'], $HTTP_SERVER_VARS['SCRIPT_NAME'] )) {
if ('' != $qstr = str_replace($HTTP_SERVER_VARS['SCRIPT_NAME'], '', $HTTP_SERVER_VARS['REQUEST_URI']) ) {
$qstr = preg_replace("/^\//", "", $qstr);
$qstr = preg_replace("/paged\/\d{0,}\//", "", $qstr);
$qstr = preg_replace("/paged\/\d{0,}/", "", $qstr);
$qstr = preg_replace("/\/$/", "", $qstr);
}
}
if ($pos = strpos(strtoupper($request), 'LIMIT')) {
$nxt_request = substr($request, 0, $pos);
}
$nxt_result = mysql_query($nxt_request);
$numposts = mysql_num_rows($nxt_result);
$max_page = ceil($numposts / $posts_per_page) ;
echo "Pages(".$max_page.") : <b>";
if ($whichpage >= 4)
echo '<a href="'.$siteurl.'/'.$blogfilename.$querystring_start.($qstr == '' ? '' : $qstr.$querystring_separator) .'paged'.$querystring_equal.'1">« First</a> ... ';
previous_posts_link($prelabel);
for($i = $whichpage - 2 ; $i <= $whichpage +2; $i++) {
if ($i >= 1 && $i <= $max_page) {
if($i == $whichpage)
echo '['.$i.'] ';
else
echo '<a href="'.$siteurl.'/'.$blogfilename.$querystring_start.($qstr == '' ? '' : $qstr.$querystring_separator) .'paged'.$querystring_equal.$i.'">'.$i.'</a> ';
}
}
next_posts_link($nxtlabel, $max_page);
if (($whichpage+2) < ($max_page))
echo ' ... <a href="'.$siteurl.'/'.$blogfilename.$querystring_start.($qstr == '' ? '' : $qstr.$querystring_separator) .'paged'.$querystring_equal.$max_page.'">Last »</a>';
echo "</b>";
}
}[/php:1:40d3d09621]
To call ths function simply use[php:1:40d3d09621]<?php pagenavi("<", ">"); ?>[/php:1:40d3d09621] It is still in developement process. Any bugs pls post here. Thanks. _________________
++ GamerZ.Per.Sg - Complex Simplicity |
|
Back to top |
|
 |
nessahead
Joined: 12 Mar 2002 Posts: 312 Location: Los Angeles, CA
|
Posted: Mon Jan 06, 2003 1:24 am Post subject: |
|
|
Splendid hack I modified it a bit for aesthetics but it works wonderfully  _________________ raar! |
|
Back to top |
|
 |
GamerZ
Joined: 15 May 2002 Posts: 537 Location: Singapore
|
Posted: Mon Jan 06, 2003 3:05 pm Post subject: |
|
|
nessahead wrote: | Splendid hack I modified it a bit for aesthetics but it works wonderfully  | hehe thanks, I think there is still bug in it. LOL _________________
++ GamerZ.Per.Sg - Complex Simplicity |
|
Back to top |
|
 |
ahotasu
Joined: 02 Dec 2002 Posts: 13 Location: Piedmont College
|
Posted: Sat Jan 25, 2003 3:47 pm Post subject: hi |
|
|
I'm getting a parse error...
It's reports the last line shown here:
Code: |
function pagenavi($prelabel='<< Previous Page', $nxtlabel='Next Page >>') {
global $p, $what_to_show, $request, $posts_per_page;
global $HTTP_SERVER_VARS, $siteurl, $blogfilename, $paged;
global $querystring_start, $querystring_equal, $querystring_separator;
if (empty($p) && ($what_to_show == 'paged')) {
|
|
|
Back to top |
|
 |
macshack
Joined: 17 Jul 2002 Posts: 1204 Location: Phoenix, Az
|
Posted: Sat Jan 25, 2003 8:24 pm Post subject: |
|
|
Hi,
I think you will find that && should be &&
Things should then work better.
Michael e |
|
Back to top |
|
 |
ahotasu
Joined: 02 Dec 2002 Posts: 13 Location: Piedmont College
|
Posted: Sat Jan 25, 2003 9:20 pm Post subject: |
|
|
thanks macshack
ok, there were two cases of && that needed to be fixed
line 5 and line 33
i dont get the error anymore but now nothing shows up.
i've tried putting
<?php pagenavi("<", ">"); ?>
both inside and outside the b2 loop but i get nothing. |
|
Back to top |
|
 |
GamerZ
Joined: 15 May 2002 Posts: 537 Location: Singapore
|
Posted: Sun Jan 26, 2003 6:01 am Post subject: |
|
|
ahotasu wrote: | thanks macshack
ok, there were two cases of && that needed to be fixed
line 5 and line 33
i dont get the error anymore but now nothing shows up.
i've tried putting
<?php pagenavi("<", ">"); ?>
both inside and outside the b2 loop but i get nothing. | what version of b2 u using? _________________
++ GamerZ.Per.Sg - Complex Simplicity |
|
Back to top |
|
 |
kichu
Joined: 23 Feb 2002 Posts: 53 Location: Chennai,India
|
Posted: Sun Jan 26, 2003 7:30 am Post subject: |
|
|
ahotasu wrote: | i've tried putting
<?php pagenavi("<", ">"); ?>
both inside and outside the b2 loop but i get nothing. |
Yes, nothing happens to me too!
http://www.cyberbrahma.com/rants/
And I use the latest b2.
Please help.
Thanks
S.K _________________ Cause something to change, you are not here for ever! |
|
Back to top |
|
 |
GamerZ
Joined: 15 May 2002 Posts: 537 Location: Singapore
|
Posted: Sun Jan 26, 2003 12:14 pm Post subject: |
|
|
kichu wrote: | ahotasu wrote: | i've tried putting
<?php pagenavi("<", ">"); ?>
both inside and outside the b2 loop but i get nothing. |
Yes, nothing happens to me too!
http://www.cyberbrahma.com/rants/
And I use the latest b2.
Please help.
Thanks
S.K | ? I saw it on your page
Pages(2) : [1] 2 > _________________
++ GamerZ.Per.Sg - Complex Simplicity |
|
Back to top |
|
 |
kichu
Joined: 23 Feb 2002 Posts: 53 Location: Chennai,India
|
Posted: Sun Jan 26, 2003 12:22 pm Post subject: |
|
|
Oh! My!
Thanks, Gamerz from Singapore (My Asian neighbour!)
I underestimated the effect of cache!
I shd have known better!
Thanks again.
Regards
S.K _________________ Cause something to change, you are not here for ever! |
|
Back to top |
|
 |
ahotasu
Joined: 02 Dec 2002 Posts: 13 Location: Piedmont College
|
Posted: Sun Jan 26, 2003 9:38 pm Post subject: |
|
|
i'm using b2 0.6.1 + ljupdate-0.2
i'm also using the last_visit hack and last 5 comments, but I don't see how those could interfere with this hack... |
|
Back to top |
|
 |
GamerZ
Joined: 15 May 2002 Posts: 537 Location: Singapore
|
Posted: Mon Jan 27, 2003 1:59 am Post subject: |
|
|
kichu wrote: | Oh! My!
Thanks, Gamerz from Singapore (My Asian neighbour!)
I underestimated the effect of cache!
I shd have known better!
Thanks again.
Regards
S.K | LOL, u from India? _________________
++ GamerZ.Per.Sg - Complex Simplicity |
|
Back to top |
|
 |
GamerZ
Joined: 15 May 2002 Posts: 537 Location: Singapore
|
Posted: Mon Jan 27, 2003 1:59 am Post subject: |
|
|
ahotasu wrote: | i'm using b2 0.6.1 + ljupdate-0.2
i'm also using the last_visit hack and last 5 comments, but I don't see how those could interfere with this hack... | ? I dun think it will interfere, i am using the last visit hack too. _________________
++ GamerZ.Per.Sg - Complex Simplicity |
|
Back to top |
|
 |
kichu
Joined: 23 Feb 2002 Posts: 53 Location: Chennai,India
|
Posted: Mon Jan 27, 2003 2:41 am Post subject: |
|
|
GamerZ wrote: | u from India? |
Yes!
In a city called "Chennai" ( a k a Madras) on the southern parts!
How are your studies!
Cheers!
S.K _________________ Cause something to change, you are not here for ever! |
|
Back to top |
|
 |
GamerZ
Joined: 15 May 2002 Posts: 537 Location: Singapore
|
Posted: Mon Jan 27, 2003 6:55 am Post subject: |
|
|
kichu wrote: | GamerZ wrote: | u from India? |
Yes!
In a city called "Chennai" ( a k a Madras) on the southern parts!
How are your studies!
Cheers!
S.K | ya so far so good =D _________________
++ GamerZ.Per.Sg - Complex Simplicity |
|
Back to top |
|
 |
|