wordpress 文章分页代码

wordpress 文章分页代码

// 分页代码
function par_pagenavi($range = 3){
    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 "<a href='" . get_pagenum_link(1) . "' class='extend' title='跳转到首页'>«</a>";}
    if($max_page > $range){
        if($paged < $range){for($i = 1; $i <= ($range + 1); $i++){echo "<a href='" . get_pagenum_link($i) ."'";
        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 "<a href='" . get_pagenum_link($i) ."'";
        if($i==$paged)echo " class='current'";echo ">$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 href='" . get_pagenum_link($i) ."'";if($i==$paged) echo " class='current'";echo ">$i</a>";}}}
    else{for($i = 1; $i <= $max_page; $i++){echo "<a href='" . get_pagenum_link($i) ."'";
    if($i==$paged)echo " class='current'";echo ">$i</a>";}}
    next_posts_link(' »');
}
}

调用代码

<div id="page"><?php par_pagenavi(5); ?></div>

css美化代码1

#page {
 width:100%;
 height:36px;
 line-height:36px;
 text-align:left;
 overflow:hidden;
 margin-left:auto;
 margin-right:auto;
 display:block;
 text-align:-moz-center;
*text-align:center;
 text-align:center
}
#page a {
 text-decoration:none;
 color:#FFF;
 background:#282828;
 display:inline-block;
 padding:9px 12px;
 margin:0 5px 0 0;
 line-height:16px;
 margin-right:3px
}
#page a:hover, #page a.current {
 color:#FFF;
 background:#32a5e7
}

css美化代码2

/*分类分页代码*/
.page_navi {
	overflow: hidden;
	width: 100%;
	text-align: center
}
.page_navi a {
	height: 36px;
	border: 1px solid #DDD;
	-webkit-border-radius: 12px;
	-moz-border-radius: 12px;
	border-radius: 12px;
	color: #888;
	text-decoration: none;
	line-height: 36px;
	margin: 2px;
	padding: 3px 8px
}
.page_navi a:hover, .page_navi a.current {
	border: 1px solid #FFBB76;
	color: #FF7200;
	font-weight: bolder
}

css美化代码3

/*pagenavi*/
.pagenavi {
	clear:both;
	text-align:center;
	font-size:0.875em;
	margin-top:2px;
}
.pagenavi a {
	display:inline-block;
	padding:0px 8px;
	border:1px solid #ddd;
	border-radius:3px;
	margin:0 3px;
}
.pagenavi a:hover, .pagenavi a.oncurrent {
	color:#fff;
	background:#E04D47;
	border:1px solid #E04D47;
	transition:all 0.4s ease 0s;
}
预见

发表评论

:?::razz::sad::evil::!::smile::oops::grin::eek::shock::???::cool::lol::mad::twisted::roll::wink::idea::arrow::neutral::cry::mrgreen: