Created
September 23, 2017 16:56
-
-
Save shangdev/fbd54b316928a3b25097980f1262c2de to your computer and use it in GitHub Desktop.
WP_Query 中 paginate_links 的使用。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* The posts | |
*/ | |
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; | |
$post_news = new WP_Query(array( | |
'post_type' => 'post', | |
'category_name' => 'news', | |
'posts_per_page' => 1, | |
'post_status' => 'publish', | |
'paged' => $paged | |
)); | |
/** | |
* The pagenation | |
*/ | |
$links = paginate_links( array( | |
'current' => max( 1, $paged ), | |
'prev_text' => __('« Previous'), | |
'next_text' => __('Next »'), | |
'total' => $post_news->max_num_pages, //WP_Query结果集中可以显示的最大页数 | |
) ); | |
echo _navigation_markup( $links, 'pagination', 'screen_reader_text' ); | |
/** | |
* The paginate style | |
*/ | |
.pagination{ | |
text-align: center; | |
padding: 47px 0 40px; | |
} | |
.pagination .nav-links{ | |
display: inline-block; | |
} | |
.pagination .nav-links .current, | |
.pagination .nav-links a{ | |
background-color: #d8d8d8; | |
display: inline-block; | |
font-size: 16px; | |
padding: 4px 10px; | |
} | |
.pagination .nav-links .current{ | |
background-color: #f0542d; | |
color: #fff; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment