?
Path : /home/admin/public_html/old/tpl/ |
Current File : /home/admin/public_html/old/tpl/page_nav.php |
<?php //require 2 variable for current page and total pages. function page_nav($page,$page_count) { function print_num($n,$page,$page_count){ //Set the url with $_GET variable. $url = $_SERVER['REQUEST_URI']; //set class for the numbers (cannot be id ..yet). //for the active page added with class 'active' $sub_nav = "sub_nav"; if(preg_match('/\bpage\b=[0-9]+/',$url,$match)) { $url = str_replace($match,'',$url); } else if(!preg_match('/\??\bpage\b=[0-9]+/',$url) && preg_match('/\?/',$url)) { $url .= "&"; } else { $url .="?"; } if($n > 0 && $n <= $page_count){ if($n == $page){ if($n == $page_count){ print(" <div class='$sub_nav active'><strong>".$n."</strong></div>"); } else { print(" <div class='$sub_nav active'><strong>".$n."</strong></div> |"); } } else{ if($n == $page_count){ print(" <a href='".$url."page=".$n."'><div class='$sub_nav'>".$n."</div></a>"); } else{ print(" <a href='".$url."page=".$n."'><div class='$sub_nav'>".$n."</div></a> |"); } } } } $nav = ''; for($i=1 ; $i <= $page_count ; $i++){ if($i == 1 && $page > 3){ $nav .= print_num(1,$page,$page_count); } if($i == 1 && $page > 4){ $nav .= print_num(2,$page,$page_count); } if($i == 1 && $page > 5){ $nav .= print_num(3,$page,$page_count); } if($i == $page-3 && $page > 6){ echo "..."; } if($page == $i){ $nav .= print_num($page-2,$page,$page_count).print_num($page-1,$page,$page_count) .print_num($page,$page,$page_count).print_num($page+1,$page,$page_count).print_num($page+2,$page,$page_count); } if($i == $page+3 && $page < $page_count-5){ echo "..."; } if($i == $page_count && $page < $page_count-4){ $nav .= print_num($page_count-2,$page,$page_count); } if($i == $page_count && $page < $page_count-3){ $nav .= print_num($page_count-1,$page,$page_count); } if($i == $page_count && $page < $page_count-2){ $nav .= print_num($page_count,$page,$page_count); } } print $nav; } // end of function page_nav. ?>