function pageNum($file,$page,$page_num,$pn=5){ /* $file 当前分页的页面 $page 当前为哪一页 $page_num 所有页面的总数 $pn 定义当前页左右两侧显示的页数,默认是5 */ //处理前翻按钮 if($page==1){ echo 'Previous'; }elseif($page==2){ echo '<a href="'.$file.'?page=1" mce_href="'.$file.'?page=1">Previous</a>'; }else{ echo '<a href="http://blog.fesite.com/wp-admin/%27.$file.%27?page=%27.%20%28$page-1%29%20.%27" mce_href="http://blog.fesite.com/wp-admin/%27.$file.%27?page=%27.%20%28$page-1%29%20.%27">Previous</a>'; } //处理中间的数字部分 for($i=1;$i<=$page_num;$i++){ if($i==1){ if($page==1){ echo '<a style="background-color: #99ccdd" mce_style="background-color: #99ccdd"><strong>'.$i.'</strong></a>'; }else{ echo '<a href="'.$file.'?page=1" mce_href="'.$file.'?page=1">1</a>'; } }elseif($i==$page_num){ if($page==$i){ echo '<a style="background-color: #99ccdd" mce_style="background-color: #99ccdd"><strong>'.$i.'</strong></a>'; }else{ echo '<a href="'.$file.'?page='.$i.'" mce_href="'.$file.'?page='.$i.'">'.$i.'</a>'; } }elseif($i<=$page+$pn && $i>=$page-$pn){ if($page==$i){ echo '<a style="background-color: #99ccdd" mce_style="background-color: #99ccdd"><strong>'.$i.'</strong></a>'; }else{ echo '<a href="'.$file.'?page='.$i.'" mce_href="'.$file.'?page='.$i.'">'.$i.'</a>'; } }else{ if($i==$page+($pn+1) || $i==$page-($pn+1)){ echo '...'; } } } //处理后翻按钮 if($page==$page_num){ echo 'Next'; }else{ echo '<a href="http://blog.fesite.com/wp-admin/%27.$file.%27?page=%27.%20%28$page+1%29%20.%27" mce_href="http://blog.fesite.com/wp-admin/%27.$file.%27?page=%27.%20%28$page+1%29%20.%27">Next</a>'; } } 测试的时候请把css也加上,否则会变形,css代码如下: <mce:style type="text/css"><!-- #page_list{ clear:both; padding:3px; margin:10px; font-size:12px; } #page_list a{ margin:5px 2px; padding:5px; height:14px; border:1px #9AAFE5 solid; text-decoration:none; color:#000; } #page_list a:hover{ background:#2E6AB1; } --></mce:style><style type="text/css" mce_bogus="1">#page_list{ clear:both; padding:3px; margin:10px; font-size:12px; } #page_list a{ margin:5px 2px; padding:5px; height:14px; border:1px #9AAFE5 solid; text-decoration:none; color:#000; } #page_list a:hover{ background:#2E6AB1; }</style> <p id="page_list"> $page=$_GET["page"]; if(!is_numeric($page)){ $page=1; } pageNum("page_num.php",$page,20,5); ?> 北京机票