wordpress 自定义分页符

先在functions.php中设置:

function get_pagenavi( $range = 4 ) {
 global $paged,$wp_query;
 if ( !$max_page ) {
 $max_page = $wp_query->max_num_pages;
 }
 if( $max_page >1 ) { 
 if( !$paged ){
 $paged = 1;
 }
 echo "<li>"; previous_posts_link('上一页');echo"</li>";
 if ( $max_page >$range ) {
 if( $paged <$range ) {
 for( $i = 1; $i <= ($range +1); $i++ ) {
 echo "<li><a href='".get_pagenum_link($i) ."'";
 if($i==$paged) echo " class='current'";echo ">$i</a></li>";
 }
 }elseif($paged >= ($max_page -ceil(($range/2)))){
 for($i = $max_page -$range;$i <= $max_page;$i++){
 echo "<li><a href='".get_pagenum_link($i) ."'";
 if($i==$paged)echo " class='current'";echo ">$i</a></li>";
 }
 }elseif($paged >= $range &&$paged <($max_page -ceil(($range/2)))){
 for($i = ($paged -ceil($range/2));$i <= ($paged +ceil(($range/2)));$i++){
 echo "<li><a href='".get_pagenum_link($i) ."'";if($i==$paged) echo " class='current'";echo ">$i</a></li>";
 }
 }
 }else{
 for($i = 1;$i <= $max_page;$i++){
 echo "<li><a href='".get_pagenum_link($i) ."'";
 if($i==$paged)echo " class='current'";echo ">$i</a></li>";
 }
 }
 echo "<li>";next_posts_link('下一页');echo"</li>"; 
 echo '<li><span>共'.$max_page.'页</span></li>'; 
 }
}

调用:

 <div class="pagination">
 <ul>
 <?php get_pagenavi();?>
 </ul>
 </div>