Home > php教程 > php手册 > wordpress免插件实现文章分页

wordpress免插件实现文章分页

WBOY
Release: 2016-06-13 10:38:20
Original
1089 people have browsed it

插件太多总是不好的,本着能不用就不用的原则,网上找了下,这个方法可行。
1.打开wp-includes下面的functions.php文件,插入这段代码:
//分页 免插件 自己加的
function par_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;} if($paged != 1){echo “ 返回首页 ”;} previous_posts_link(‘ 上一页 ‘);
if($max_page > $range){ if($paged if($i==$paged)echo ” class=’current’”;echo “>$i”;}} elseif($paged >= ($max_page – ceil(($range/2)))){ for($i = $max_page – $range;
$i if($i==$paged)echo ” class=’current’”;echo “>$i”;}} elseif($paged >= $range && $paged $i if($i==$paged) echo ” class=’current’”;echo “>$i”;}}} else{for($i = 1;
$i if($i==$paged)echo ” class=’current’”;echo “>$i”;}} next_posts_link(‘ 下一页 ‘);
if($paged != $max_page){echo “ 最后一页 ”;}} }
2.在主题目录下找到index.php,search.php,archive.php这三个文件,主题不同当然名字也并不一定相同,就找主页,搜索页,翻页这三个文件就行,然后添加

到原先的分页代码,也就是替换这个分页代码




3.添加样式代码到style.css中。
.page_navi{width:100%;height:36px;line-height:36px;text-align:center;overflow:hidden;padding-top:1em;}
.page_navi a{padding:3px 8px;margin:2px;text-decoration:none;color:#888;border:1px solid #ccf;}
.page_navi a:hover,.page_navi a.current{border:1px solid #356aa0;color:#356aa0;font-weight:bolder;}
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template