方法步骤:
- 登陆博客后台,在主题编辑窗口下选择functions.php文件,在该文件中添加以下代码(代码添加在“?>”前面或者“<?php”后面):
function par_pagenavi($range = 9){
global $paged, $wp_query;
if ( !$max_page ) {$max_page = $wp_query->max_num_pages;}
echo "<span> ".$paged." / ".$max_page." </span> ";
if($max_page > 1){if(!$paged){$paged = 1;}
if($paged != 1){echo "<a class=\"extend\" title=\"跳转到首页\" href=\"" . get_pagenum_link(1) . "\"> 第一页 </a>";}
if($max_page > $range){
if($paged < $range){for($i = 1; $i <= ($range + 1); $i++){echo "<a class=\"current\" href=\"" . get_pagenum_link($i) ."\">$i</a>";}}
elseif($paged >= ($max_page - ceil(($range/2)))){
for($i = $max_page - $range; $i <= $max_page; $i++){echo "<a class=\"current\" href=\"" . get_pagenum_link($i) ."\">$i</a>";}}
elseif($paged >= $range && $paged < ($max_page - ceil(($range/2)))){
for($i = ($paged - ceil($range/2)); $i <= ($paged + ceil(($range/2))); $i++){echo "<a class=\"current\" href=\"" . get_pagenum_link($i) ."\">$i</a>";}}}
else{for($i = 1; $i <= $max_page; $i++){
if ($i == $paged) {
echo "$i";
}
else {
echo "<a class=\"current\" href=\"" . get_pagenum_link($i) ."\">$i</a>";
}
}}
if($paged != $max_page){echo "<a class=\"extend\" title=\"跳转到最后一页\" href=\"" . get_pagenum_link($max_page) . "\"> 最后一页 </a>";}}
} - 然后分别选择index.php、search.php、archive.php,在这些文件中找到代码:
1 2
<?php next_posts_link('« Previous Entries') ?> <?php previous_posts_link('Next Entries »') ?>
- 把2中的两行代码替换为
1 2 3
<div> <?php par_pagenavi(6); ?> </div>
- 点击style.css进入编辑窗口,在任意位置添加样式代码:
.page_navi{width:100%;height:36px;line-height:36px;text-align:center;overflow:hidden;padding-top:1em; font-weight:bold;}
.page_navi span{color:#999999}
.page_navi a{padding:3px 8px;margin:2px;text-decoration:none;color:#FF6600;}
.page_navi a:hover,.page_navi a.current{color:#FF6600;font-weight:bolder;} - 保存更新后,即可看到不用博客插件实现的分页效果。演示看博客吧
转自:http://www.boke8.net/wordpress-page-navigation.html 后修改
WordPress 无需插件实现文章列表分页导航:等您坐沙发呢!