function theme_echo_pagenavi(){
global $request, $posts_per_page, $wpdb, $paged;
$maxButtonCount = 9; //The maximum number of links displayed
if (!is_single()) {
if(!is_category()) {
preg_match('#FROMs(.*)sORDER BY#siU', $request, $matches);
} else {
preg_match('#FROMs(. *)sGROUP BY#siU', $request, $matches);
}
$fromwhere = $matches[1];
$numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID ) FROM $fromwhere");
$max_page = ceil($numposts /$posts_per_page);
if(empty($paged)) {
$paged = 1;
}
$ start = max(1, $paged - intval($maxButtonCount/2));
$end = min($start + $maxButtonCount - 1, $max_page);
$start = max(1, $end - $maxButtonCount + 1);
if($paged == 1){
echo "
Homepage";
echo "
Previous Page< /span>";
}else{
echo 'Homepage';
echo 'Previous page';
}
for($i=$start; $i<=$end; $i++){
if($i == $paged) {
echo "[$ i]";
} else {
echo '[' .$i.']';
}
}
if($paged == $max_page){
echo "Next page";
echo "last page ";
}else{
echo 'Next page';
echo '< ;span>Last page';
}
echo "Total {$numposts} records, {$max_page} pages.";
}
}