wp-pagenavi not working

CardinalPPC

Newbie
Joined
Jul 23, 2009
Messages
35
Reaction score
0
I'm creating an arcade site using the WPArcade script and I'm almost done. The only issue right now is that the pagenavi plugin is showing white rectangles where the numbers should be. I've gone throughout the plugin, deleted and reinstalled it, and I still can't get it to work. Any suggestions?
 
Hey, you. Here is the solution. It's working without plugin, very good for you.

1. Paste this code into functions.php or custom-functions.php
PHP:
<?php
#Page Navi

function page_navi($before = '', $after = '') {
	global $wpdb, $wp_query;
	
	$request = $wp_query->request;
	$posts_per_page = intval(get_query_var('posts_per_page'));
	$paged = intval(get_query_var('paged'));
	$numposts = $wp_query->found_posts;
	$max_page = $wp_query->max_num_pages;
	
	if(empty($paged) || $paged == 0) {
		$paged = 1;
	}
	$pages_to_show = 5;
	$pages_to_show_minus_1 = $pages_to_show-1;
	$half_page_start = floor($pages_to_show_minus_1/2);
	$half_page_end = ceil($pages_to_show_minus_1/2);
	$start_page = $paged - $half_page_start;
	if($start_page <= 0) {
		$start_page = 1;
	}
	$end_page = $paged + $half_page_end;
	if(($end_page - $start_page) != $pages_to_show_minus_1) {
		$end_page = $start_page + $pages_to_show_minus_1;
	}
	if($end_page > $max_page) {
		$start_page = $max_page - $pages_to_show_minus_1;
		$end_page = $max_page;
	}
	if($start_page <= 0) {
		$start_page = 1;
	}
	
	echo $before.'<center><div class="page_navi">'."\n";
	if ($start_page >= 2 && $pages_to_show < $max_page) {
		$first_page_text = "First";
		echo '<a href="'.get_pagenum_link().'" title="'.$first_page_text.'">'.$first_page_text.'</a>';
	}
	previous_posts_link('«');
	for($i = $start_page; $i  <= $end_page; $i++) {						
		if($i == $paged) {
			echo '<span class="current">'.$i.'</span>';
		} else {
			echo '<a href="'.get_pagenum_link($i).'">'.$i.'</a>';
		}
	}
	next_posts_link('»');
	if ($end_page < $max_page) {
		$last_page_text = "Last";
		echo '<a href="'.get_pagenum_link($max_page).'" title="'.$last_page_text.'">'.$last_page_text.'</a>';
	}
	echo '</div></center>'.$after."\n";
}
?>
2. Call page navi in theme file, for example: index.php, archive.php...
PHP:
  <div class="page_navi">
    <?php page_navi(); ?>
  </div>
3. Style for page navi, copy & paste this code into style.css, you can edit :P

.page_navi{padding:10px 0 10px 10px;}
.page_navi a,.page_navi a:link,.page_navi a:visited{text-decoration:none;border:1px solid #ccc;color:#2b74b4;background-color:#fff;font-weight:700;margin:2px;padding:2px 4px;}
.page_navi a:active,.page_navi a:hover{text-decoration:none;border:1px solid #2b74b4;color:#fff;background-color:#0F0;margin:2px;padding:2px 4px;}
.page_navi span.current{font-weight:700;border:1px solid #2b74b4;color:#fff;background-color:#03C;margin:2px;padding:2px 4px;}

Good luck! :P
 
Back
Top