Twenty Twelve 作为 WordPress 官方主题,小清新。但是,有一点我不喜欢,没有 Page Navi,而是采用传统方式。这也许是为了保证响应式设计不错位。但是,其实可以微调一下,我拿我有限的设备测试了一下,貌似不错位。
1)修改主题 Style.CSS,加入:
.page-numbers { padding: 0 5px 5px; }
2)修改主题的 Functions.PHP,加入:
<?php function nikbobo_pagenavi(){ global $wp_query; $big = 999999999; // need an unlikely integer $pagination = array( 'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ), 'format' => '', 'total' => $wp_query->max_num_pages, 'current' => max( 1, get_query_var('paged') ), 'prev_text' => '<span class="meta-nav">←</span>', 'next_text' => '<span class="meta-nav">→</span>', 'show_all' => False, 'end_size' => 1, 'mid_size' => 1 ); echo paginate_links($pagination); } ?>
3)在主题的 Functions.php,查找:
function twentytwelve_content_nav( $html_id ) { global $wp_query; $html_id = esc_attr( $html_id ); if ( $wp_query->max_num_pages > 1 ) : ?> <nav id="<?php echo $html_id; ?>" class="navigation" role="navigation"> <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3> <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentytwelve' ) ); ?></div> <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentytwelve' ) ); ?></div> </nav><!-- #<?php echo $html_id; ?> .navigation --> <?php endif; }
替换为:
function twentytwelve_content_nav( $html_id ) { global $wp_query; $html_id = esc_attr( $html_id ); if ( $wp_query->max_num_pages > 1 ) : ?> <nav id="<?php echo $html_id; ?>" class="navigation" role="navigation"> <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3> <?php nikbobo_pagenavi(); ?> </nav><!-- #<?php echo $html_id; ?> .navigation --> <?php endif; }
大功告成!
有没有发现?这其实和我的 ProwerV6 主题添加 WordPress PageNavi 教程是差不多的,唯一的区别就是 CSS。
话说,Twenty Thirteen 的 CSS,我也弄出来了,有时间再发吧!