为twentythirteen子主题添加pagenavi分页导航:方法同为twentytwelve子主题添加pagenavi分页导航一样,修改function.php文件即可,添加一段代码即可实现。
twentythirteen主题是暖色系,是WordPress 3.6的默认主题。www.anaids.com 就是利用twentythirteen主题修改的子主题。
twentythirteen主题和twentytwelve一样,分页导航也不咋的。
如何修改twentythirteen子主题的function.php实现pagenavi,我的方法如下。
修改function.php
打开子主题的function.php,添加如下代码:
- /**
- * Display new navigation to next/previous pages when applicable
- */
- function twentythirteen_paging_nav() {
- global $wp_query;
- if ( $wp_query->max_num_pages > 1 ) : ?>
- <?php
- /**
- Call our new function to see if any pagination plugins are active
- If one of the plugins is active then exit this function
- If none of the plugins are active use the default styles
- */
- ?>
- <?php /* Is the Pagenavi plugin active ? */ ?>
- <?php if( function_exists('wp_pagenavi') ) : ?>
- <?php wp_pagenavi(); ?>
- <?php return true; //Get out of here! ?>
- <?php endif; ?>
- <?php endif;
- }
- endif; // twentythirteen_paging_nav
同样,如果子主题的function.php未添加其它任何代码,前面要加<?php
美化pagenavi分页导航
在twentythirteen子主题添加如下代码即可
- /* Using !important to override PageNavi CSS */
- .wp-pagenavi {
- background-color: #e8e5ce;
- padding:18px;
- }
- .wp-pagenavi a, .wp-pagenavi a:link, .wp-pagenavi span {
- color:#444!important;
- font-style:normal;
- margin:7px !important;
- padding:7px !important;
- border-radius: 7px;
- -moz-border-radius: 7px;
- -webkit-border-radius: 7px;
- }
- .wp-pagenavi a:visited {
- border:1px solid #ccc !important;
- color:#666 !important;
- }
- .wp-pagenavi a:hover {
- border:1px solid #4285F4 !important;
- color:#666 !important;
- }
- .wp-pagenavi a:active {
- border:1px solid #666 !important;
- color:#666 !important;
- }
- .wp-pagenavi span.pages {
- display: none;
- }
- .wp-pagenavi span.current {
- background: #42A2CE !important;
- border: none !important;
- color:#fff!important;
- font-style:normal;
- margin:7px !important;
- padding:7px !important;
- border-radius: 7px;
- -moz-border-radius: 7px;
- -webkit-border-radius: 7px;
- }
- .wp-pagenavi span.extend {
- background-color:#FFF;
- border:1px solid #42A2CE;
- color:#000;
- margin:2px;
- padding:2px 4px;
- }
为了和原twentythirteen主题的导航一致,添加了一个背景。