Home  >  Article  >  Backend Development  >  WordPress plug-in-free implementation of article paging_PHP tutorial

WordPress plug-in-free implementation of article paging_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:39:49804browse

It is always a bad thing to have too many plug-ins. Based on the principle of not using them if you can, I searched online and found that this method is feasible.
1. Open the functions.php file under wp-includes and insert this code:
//Paging is added by the plugin itself
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 " Return to home page";} previous_posts_link( ' Previous page');
if($max_page > $range){ if($paged < $range){for($i = 1; $i <= ($range + 1); $ i++){echo "if($i==$paged)echo ” class='current'";echo ">$i< ;/a>”;}} elseif($paged >= ($max_page – ceil(($range/2)))){ for($i = $max_page – $range;
$i <= $max_page; $i++){echo "
if($i==$paged)echo ” class='current'";echo " >$i”;}} elseif($paged >= $range && $paged < ($max_page – ceil(($range/2)))){ for($i = ($paged – ceil($range/2));
$i <= ($paged + ceil(($range/2))); $i++){echo “if($i==$paged) echo ” class='current'";echo ">$i";}}} else{for($i = 1;
$i <= $max_page; $i++){echo "if($i==$paged)echo " class='current'";echo ">$i";}} next_posts_link(' next page');
if($paged != $max_page){echo " Last page";}} }
2. In the theme directory Find the three files index.php, search.php, and archive.php. The themes are different and of course the names are not necessarily the same. Just find the home page, search page, and page through these three files, and then add

< ;?php par_pagenavi(4); ?>
To the original paging code, that is, replace this paging code

< ;/div>


3. Add style code to 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;}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486268.htmlTechArticleToo many plug-ins are always bad. Based on the principle of not using them if you can, I searched online and found this The method works. 1. Open the functions.php file under wp-includes and insert this code: //Min...
Statement:
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