//注意事项:1->10为每页数量 //1、建立function.php //pagenav function pagenav($query_string){ global $posts_per_page, $paged; $my_query = new WP_Query($query_string ."&posts_per_page=-1"); $total_posts = $my_query->post_count; if(empty($paged))$paged = 1; $prev = $paged - 1; $next = $paged + 1; $range = 4; // only edit this if you want to show more page-links $showitems = ($range * 2)+1; $pages = ceil($total_posts/$posts_per_page); if(1 != $pages){ echo "<div class='pagination'>"; echo ($paged > 2 && $paged+$range+1 > $pages && $showitems < $pages)? "<a href='".get_pagenum_link(1)."'>最前</a>":""; echo ($paged > 1 && $showitems < $pages)? "<a href='".get_pagenum_link($prev)."'>上一页</a>":""; for ($i=1; $i <= $pages; $i++){ if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )){ echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>"; } } echo ($paged < $pages && $showitems < $pages) ? "<a href='".get_pagenum_link($next)."'>下一页</a>" :""; echo ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) ? "<a href='".get_pagenum_link($pages)."'>最后</a>":""; echo "</div>\n"; } } //2、css样式 /*分页的样式 */ .pagination{ margin:0 10px 10px 15px;line-height:23px;text-align:center;} .pagination span, .pagination a{font-size:12px;margin: 2px 6px 2px 0;background:#fff;border:1px solid #ccc;color:#787878;padding:2px 5px 2px 5px;text-decoration:none;} .pagination a:hover{background: #8cb900;border:1px solid #436206;color:#fff;font-size:12px;padding:2px 5px 2px 5px;} .pagination .current{background: #8cb900;border:1px solid #436206;color:#fff;font-size:12px;padding:2px 5px 2px 5px;} //3、调用页 <?php if ($posts_perpage) { ?> <?php $postsperpage = $posts_perpage; ?> <?php } else { ?> <?php $postsperpage = 10; ?> <?php } ?> <?php $categoryID=$cat; $wp_query = new WP_Query('cat=' . $categoryID. 'orderby=date&order=desc&posts_per_page='.$postsperpage.'&paged='.$paged); ?> <?php while (have_posts()) : the_post(); ?> <ul> <li><span> <?php the_date_xml(); ?> </span><span></span><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> <?php the_title(); ?> </a></li> </ul> <?php endwhile; ?> <?php pagenav($query_string); ?> //调用