WordPress主题开发之添加文章列表分页功能
function get_pagenavi( $range = 4 ) {
global $paged,$wp_query;
if ( !$max_pc N R D x , d =age ) {
$max_page = $wp_query->max_num_7 M Y _ j J K 8pages;
}[ g e ) J 5 0 G c
if( $max_page >1 ) {
if( !$paged ){
$paged = 1;
}
echo "<li>"; previous_posts_link('上一页');echo"</li>";
if ( $max_page >$range ) {
if( $p= X Uaged <N / a 9 P ! -$range ) {
for( $i = 1; $i <= ($range +1); $i++ ) {
echo "<li><a href='".get_pp s eagenum_link($i) ."'"7 o a;0 @ T :
iN n -f($i==$paged) echo " class='current'";echo ">$i</a></li>";
}
}elseif($pag9 ( J x aed >= ($max_page D i ~ ! m y -ceil(($range/2)))){
for($i = $max_page -$range;$i <= $max_page;$i++){
echo "<li><a href='".K = ) 2 C z w t cget_pagenum_link($i) ."'";
if($i==$paged)echo " class1 B f s V 1='current'";echo "&g[ ? F bt;$i</a></li>";
}
}elseif($paged >= $range &&$paged <($max_page -ceil(($D ~ m ; 6 Hrange/2)))){
for($i = ($paged -ceil($range/2));$i <= ($paged +ceil(($range/2))] h I k % z n);$i++){
echo "<li><a href='P 6 T @ ,".get_pagenum_link($i) ."'";if($i==$paged) echo " class='current'"u d 4 C q M R Q;echo ">$i</a></li>";
}
}
}else{
for($i =. , z 1;$i <= $max_page;$i++){
echo "<li><z E Ya href='".get_pagenum_link($i) ."'";
if($i==$pageG f G y P { sd)echo " class='current'";echo ">$i</a></li>";
}
}
echo "<li>";next_posts_link('下一页A B , ^ m h }');echop Q F _ % 7 ( }"</li>";
echo 'A k p Q = 3 ) {<li><span>共'.$max_page.'页&l{ 3 0 $t;/span></li>';
}
}
将上面的代码放在WordPress主题文件目n K U b Q录下的function. [ { 5s.php中,然后在你需要的地方使用下面的代码调用:c 6 ] 1 .| P T o . M k b E {
<?php get_pagenavi();?>