Computer Tech, Gaming & Electronics THIS SPACE OPEN FOR ADVERTISEMENT. YOU SHOULD BE ADVERTISING HERE! Silicon Valley.
Tips & tricks, tech support, home theatre, online gaming, reviews, latest news...
11-05-2011, 12:25 AM
#1 Banned (ABWS)
Join Date: Mar 2011
Location: burnaby
Posts: 1,734
Thanked 642 Times in 217 Posts
Failed 269 Times in 70 Posts
PHP Pros... need some help
Well I am trying to get a simple pagination to display all current pages.
The original code displayed
" Prev 1 2 3 ... 100 101 103 Next"
I want it to go like
"Prev 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Next"
Pretty much to show ALL pages
the code is in the spoiler please help
Spoiler!
<?php
defined('_VALID') or die('Restricted Access!');
function template_plugin_pagination($options=array(), $url, $index=2, $id=NULL)
{
$page = $options['page'];
$total_pages = $options['total_pages'];
$prev_page = $options['prev_page'];
$next_page = $options['next_page'];
$output = array();
if ($page != 1 ) {
$output[] = '<li><a href="'.pag_strip($prev_page, $url).'"'.pag_id($prev_page, $id, 'prev_page').' class="prevnext">'.__('PREV').'</a></li>';
}
if ($total_pages > (($index*2)+3) && $page >= ($index+3)) {
$output[] = '<li><a href="'.pag_strip(1, $url).'"' .pag_id(1, $id). '>1</a></li>';
$output[] = '<li><a href="'.pag_strip(2, $url).'"' .pag_id(2, $id). '>2</a></li>';
}
if ($page > $index+3) {
$output[] = '<li><span style="color: #373737;"> ... </span></li>';
}
for ($i=1; $i<=$total_pages; $i++) {
if ($page == $i ) {
$output[] = '<li><span class="currentpage">' .$page. '</span></li>';
} elseif ( ($i >= ($page-$index) && $i < $page) OR ($i <= ($page+$index) && $i > $page) ) {
$output[] = '<li><a href="'.pag_strip($i, $url).'"'.pag_id($i, $id).'>'.$i.'</a></li>';
}
}
if ($page < ($total_pages-6)) {
$output[] = '<li><span style="color: #373737;"> ... </span></li>';
}
if ($total_pages > (($index*2)+3) && $page <= $total_pages-($index+3)) {
$output[] = '<li><a href="'.pag_strip(($total_pages-2), $url).'"'.pag_id(($total_pages-2), $id).'>'.($total_pages-2).'</a></li>';
$output[] = '<li><a href="'.pag_strip(($total_pages-1), $url).'"'.pag_id(($total_pages-1), $id).'>'.($total_pages-1).'</a></li>';
}
if ($page != $total_pages) {
$output[] = '<li><a href="'.pag_strip($next_page, $url).'"'.pag_id($next_page, $id, 'next_page').' class="prevnext">'.__('NEXT').'</a></li>';
}
return implode('', $output);
}
function pag_id($page, $id=NULL, $add=NULL)
{
if ($id) {
return ' id="'.$id.'_'.$page.($ad) ? '_'.$add.'" ' : '"';
}
}
function pag_strip($page, $url)
{
if ($url === CURRENT_URL) {
if (isset($_GET['page'])) {
return str_replace('#PAGE#', 'page='.$page, preg_replace('/page=(\w+)/i', '#PAGE#', $url));
} else {
return $url.((strpos($url, '?')) ? '&' : '?').'page='.$page;
}
} else {
if ($page === 1) {
return str_replace('/#PAGE#', '', $url);
} else {
return str_replace('#PAGE#', $page, $url);
}
}
}
11-05-2011, 11:12 AM
#2 Proud to be called a RS Regular!
Join Date: Aug 2008
Location: Vancouver
Posts: 130
Thanked 10 Times in 9 Posts
Failed 40 Times in 5 Posts
I am no PHP pro, but i think you can just replace this whole part with the code i entered underneath.
I could be wrong though, only spend a few minutes looking through it, test it out and let me know if there is a problem
Code:
if ($total_pages > (($index*2)+3) && $page >= ($index+3))
{
$output[] = '<li><a href="'.pag_strip(1, $url).'"' .pag_id(1, $id). '>1</a></li>';
$output[] = '<li><a href="'.pag_strip(2, $url).'"' .pag_id(2, $id). '>2</a></li>';
}
if ($page > $index+3)
{
$output[] = '<li><span style="color: #373737;"> ... </span></li>';
}
for ($i=1; $i<=$total_pages; $i++)
{
if ($page == $i )
{
$output[] = '<li><span class="currentpage">' .$page. '</span></li>';
} elseif ( ($i >= ($page-$index) && $i < $page) OR ($i <= ($page+$index) && $i > $page) )
{
$output[] = '<li><a href="'.pag_strip($i, $url).'"'.pag_id($i, $id).'>'.$i.'</a></li>';
}
}
if ($page < ($total_pages-6))
{
$output[] = '<li><span style="color: #373737;"> ... </span></li>';
}
if ($total_pages > (($index*2)+3) && $page <= $total_pages-($index+3))
{
$output[] = '<li><a href="'.pag_strip(($total_pages-2), $url).'"'.pag_id(($total_pages-2), $id).'>'.($total_pages-2).'</a></li>';
$output[] = '<li><a href="'.pag_strip(($total_pages-1), $url).'"'.pag_id(($total_pages-1), $id).'>'.($total_pages-1).'</a></li>';
} Code:
for ($i=1; $i<=$total_pages; $i++) {
if ($page == $i )
{
$output[] = '<li><span class="currentpage">' .$page. '</span></li>';
}
else
{
$output[] = '<li><a href="'.pag_strip($i, $url).'"'.pag_id($i, $id).'>'.$i.'</a></li>';
}
}
11-05-2011, 11:42 PM
#3 Banned (ABWS)
Join Date: Mar 2011
Location: burnaby
Posts: 1,734
Thanked 642 Times in 217 Posts
Failed 269 Times in 70 Posts
Got it to work but can't make it go into 2 or 3 different rows to fit on one page
Spoiler!
function template_plugin_pagination($options=array(), $url, $index=2, $id=NULL)
{
$page = $options['page'];
$total_pages = $options['total_pages'];
$prev_page = $options['prev_page'];
$next_page = $options['next_page'];
$output = array();
if ($page != 1 ) {
$output[] = '<li><a href="'.pag_strip($prev_page, $url).'"'.pag_id($prev_page, $id, 'prev_page').'>'.__('PREV').'</a></li>';
}
for ($i=1; $i<=$total_pages; $i++) {
if ($page == $i ) {
$output[] = '<li><span>' .$page. '</span></li>';
} else {
$output[] = '<li><a href="'.pag_strip($i, $url).'"'.pag_id($i, $id).'>'.$i.'</a></li>';
}
}
if ($page != $total_pages) {
$output[] = '<li><a href="'.pag_strip($next_page, $url).'"'.pag_id($next_page, $id, 'next_page').'>'.__('NEXT').'</a></li>';
}
return implode('', $output);
}
11-06-2011, 12:42 AM
#4 Banned (ABWS)
Join Date: Mar 2011
Location: burnaby
Posts: 1,734
Thanked 642 Times in 217 Posts
Failed 269 Times in 70 Posts
got it changed css file added float: left padding-bottom: 20px
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT -8. The time now is 12:12 AM .