如何在Thesis主题中启用WP-PageNavi插件

站目前使用的Thesis主题是非常出名的Theme Framework之一,自定义程度相当高,SEO高度优化,当然,价格不菲:主体框架 $87,如果加上皮肤包的话,就超过$100了。

这么好的主题,功能强大,便于使用,后台配置选项非常多,但是最近一个插件闹得我很是烦恼:WP-PageNavi,这个最出名的分页导航插件,在Thesis主题中安装启用后并没有生效。也就是说,需要自己修改代码了。然而这个功能强大的主题文件繁多,代码又很高深,居然没有传统的single.php, page.php文件,也难怪Theme Framework 和普通的Theme是不一样的。经过好几天的琢磨,今天终于找到了解决办法,并且成功显示分页导航了! 下面分享经验:

打开/wp-content/themes/thesis_18/lib/functions/content.php 文件,定位到以下代码:

function thesis_post_navigation() {
    global $wp_query;

    if ($wp_query->is_home || $wp_query->is_archive || $wp_query->is_search) {
        if ($wp_query->max_num_pages > 1) {
            $previous = apply_filters('thesis_previous', __('Previous Entries', 'thesis'));
            $next = apply_filters('thesis_next', __('Next Entries', 'thesis'));
            echo "\t\t\t<div class=\"prev_next\">\n";

            if ($wp_query->query_vars['paged'] <= 1) {
                echo "\t\t\t\t<p class=\"previous\">";
                next_posts_link($previous);
                echo "</p>\n";
            }
            elseif ($wp_query->query_vars['paged'] < $wp_query->max_num_pages) {
                echo "\t\t\t\t<p class=\"previous floated\">";
                next_posts_link($previous);
                echo "</p>\n";

                echo "\t\t\t\t<p class=\"next\">";
                previous_posts_link($next);
                echo "</p>\n";
            }
            elseif ($wp_query->query_vars['paged'] >= $wp_query->max_num_pages) {
                echo "\t\t\t\t<p class=\"next\">";
                previous_posts_link($next);
                echo "</p>\n";
            }

            echo "\t\t\t</div>\n\n";
        }
    }
}

将这段代码改为为:

function thesis_post_navigation() {
	global $wp_query;
	wp_pagenavi();
}

pagenavi

 

此时,WP-PageNavi已经可以正常显示了,但是样式很丑,和Thesis主题很不协调。现提供一段很好的CSS代码,替换掉pagenavi- css.css内容(确保已启用该文件) 或者 插入Thesis的custom.css文件中(不启用pagenavi- css.css)插入具体效果参看本站的导航样式。

.wp-pagenavi { margin: 15px 0px 15px 0px; }
.wp-pagenavi a, .wp-pagenavi a:link { font-size:14px; padding: 5px 9px; margin: 2px; text-decoration: none; border: 1px solid #e1e1c8; color: #413f36; background-color: #eeeeee; }
.wp-pagenavi a:visited { font-size:14px; padding: 5px 9px; margin: 2px; text-decoration: none; border: 1px solid #e1e1c8; color: #413f36; background-color: #eeeeee; }
.wp-pagenavi a:hover { font-size:14px; border: 1px solid #608e7a; color: #FFF; background-color: #75040b; }
.wp-pagenavi a:active { font-size:14px; padding: 5px 9px; margin: 2px; text-decoration: none; border: 1px solid #e1e1c8; color: #413f36; background-color: #eeeeee; }
.wp-pagenavi span.pages { font-size:14px; padding: 5px 9px; margin: 2px 2px 2px 2px; color: #000000; border: 1px solid #e1e1c8; color: #413f36; background-color: #eeeeee; }
.wp-pagenavi span.current { font-size:14px; padding: 5px 9px; margin: 2px; font-weight: bold; border: 1px solid #608e7a; color: #FFF; background-color: #75040b; }
.wp-pagenavi span.extend { font-size:14px; padding: 5px 9px; margin: 2px; border: 1px solid #608e7a; color: #FFF; background-color: #75040b; }

  1 Comment

  1. Moshow Cc   •  

    哎呀,老爱了。
    我也搞定了哈哈。
    欢迎交流。

Leave a Reply

Your email address will not be published. Required fields are marked *