wordpress自定义分页
文章描述:
wordpress如何自定义分页样式呢?wordpress默认的分页只有上一页和下一页,是主题默认的样式,用户体验起来非常的不好,那么怎么自定义分页样式?
默认分页
WordPress默认的分页函数
posts_nav_link();
自定义分页
分页函数
functions.php自定义函数里面有首页、尾页、上一页、下一页、显示几页已经总共有多少数据
function MBThemes_paging() {
$p = 3;
if ( is_singular() ) return;
global $wp_query, $paged;
$max_page = $wp_query->max_num_pages;
if ( $max_page == 1 ) return;
echo '<div class="pagination"><ul>';
if ( empty( $paged ) ) $paged = 1;
// echo '<span class="pages">Page: ' . $paged . ' of ' . $max_page . ' </span> ';
if ( $paged > 1 ) p_link( 1, '首页' );
echo '<li class="prev-page">';
previous_posts_link('上一页');
echo '</li>';
//if ( $paged > $p + 1 ) p_link( 1 );
//if ( $paged > $p + 2 ) echo "<li><span>···</span></li>";
for ( $i = $paged - $p; $i <= $paged + $p; $i++ ) {
if ( $i > 0 && $i <= $max_page ) $i == $paged ? print "<li class=\"active\"><span>{$i}</span></li>" : p_link( $i );
}
//if ( $paged < $max_page - $p - 1 ) echo "<li><span> ... </span></li>";
//if ( $paged < $max_page - $p ) p_link( $max_page);
echo '<li class="next-page">';
next_posts_link('下一页');
echo '</li>';
p_link( $max_page, '尾页' );
//echo '<li><span>共 '.$max_page.' 页</span></li>';
echo '</ul></div>';
}
function p_link( $i, $title = '' ) {
if ( $title == '' ) $title = "{$i}";
echo "<li><a href='", esc_html( get_pagenum_link( $i ) ), "'>{$title}</a></li>";
}
function p_curr_link( $i) {
echo '<li><span class="page-numbers current">'.$i.'</span></li>';
}
分页样式
/* pages */
.pagination{margin:30px 0;padding:0 10px;text-align:center;font-size:12px;display:block;border-radius:0}
.excerpts .pagination{margin-bottom: 10px;}
.pagination ul{display:inline-block !important;*display:inline;*zoom:1;margin-left:0;margin-bottom:0;padding:0}
.pagination ul > li{display:inline}
.pagination ul > li > a,.pagination ul > li > span{margin:0 2px;float:left;padding:5px 12px;background-color:#ddd;color:#666;border-radius:2px;opacity:.88}
.pagination ul > li > a:hover,.pagination ul > li > a:focus{opacity:1}
.pagination ul > .active > a,.pagination ul > .active > span{background-color:#1d1d1d;color:#fff}
.pagination ul > .active > a,.pagination ul > .active > span{cursor:default}
.pagination ul > li > span,.pagination ul > .disabled > span,.pagination ul > .disabled > a,.pagination ul > .disabled > a:hover,.pagination ul > .disabled > a:focus{color:#999999;background-color:transparent;cursor:default;}
使用分页
使用自定义分页只需替换掉默认的分页即可
<?php MBThemes_paging();?>
发布时间:2021/08/10
发表评论