frontopen2真的是一款非常棒的wordpress主题,有兴趣的同学可以试试看。后面附上一张该主题的示例图。我决定将该主题长期使用,但是也遇到了一些问题。虽然我不懂PHP,能看懂一些html语言,但是也勉强可以照猫画虎般的通过猜测对主题做一些修改。为了防止以后升级主题后忘记修改之处,专门写一篇文章来记录一下对fo2的修改。

关于“围观次数”的修改

该主题默认带有围观次数的统计,但是我发现我的好像有些问题,访问后次数并没有增加。所以我就索性继续用以前的插件wp-postviews,不过该主题完美支持该插件。只需对主题文件里面的loop.php和loop-single.php文件做一些小小的修改。找到包含“围观”部分的代码,进行如下修改:

修改前的代码:

loop.php文件(原文件第60行):

<aside class="iititle"><span><i class="icon-user icon-large"></i> <?php the_author_posts_link(); ?></span><?php printf( __( '<span><i class="icon-folder-open icon-large"></i> %2$s</span>', 'frontopen' ), 'i1', get_the_category_list( ', ' ) ); ?><?php if(get_option('themes_fo2_view_time') && getPostViews(get_the_ID()));else{ ?><span><i class="icon-eye-open icon-large"></i> 围观<?php echo getPostViews(get_the_ID()); ?>次</span><?php }?><span><i class="icon-comment-alt icon-large"></i> <?php comments_popup_link( __( 'Leave a comment', 'frontopen' ), __( '1 Comment', 'frontopen' ), __( '% Comments', 'frontopen' ) ); ?></span></aside>

loop-single.php(原文件第11行) :

<span><i class="icon-user icon-large"></i> <?php the_author_posts_link(); ?></span><?php printf( __( '<span><i class="icon-folder-open icon-large"></i> %2$s</span>', 'frontopen' ), 'i1', get_the_category_list( ', ' ) ); ?><span><i class="icon-eye-open icon-large"></i> 围观<i id="number"><?php echo getPostViews(get_the_ID());if($_SERVER["QUERY_STRING"])setPostViews(get_the_ID())?></i><script type="text/javascript">jQuery(function($){$.get("<?php bloginfo('url')?>/fo_ajax?ajax=getPostViews&postID=<?php echo get_the_ID()?>",function(data){if(data.length < 10)$('#number').text(data)});})</script>次</span><span><i class="icon-comment-alt icon-large"></i> <?php comments_popup_link( __( 'Leave a comment', 'frontopen' ), __( '1 Comment', 'frontopen' ), __( '% Comments', 'frontopen' ) ); ?></span><span><i class="icon-pencil icon-large"></i> 编辑日期:<time><?php the_modified_time('Y-m-d')?></time></span><span><i class="icon-zoom-in icon-large"></i> 字体:<a href="javascript:;" onclick="checkFontSize(18)">大</a> <a href="javascript:;" onclick="checkFontSize(16)">中</a> <a href="javascript:;" onclick="checkFontSize(14)">小</a></span><?php if(function_exists('the_views')) { the_views(); } ?>

修改后的代码:

loop.php文件(原文件第60行):

<aside class="iititle"><span><i class="icon-user icon-large"></i> <?php the_author_posts_link(); ?></span><?php printf( __( '<span><i class="icon-folder-open icon-large"></i> %2$s</span>', 'frontopen' ), 'i1', get_the_category_list( ', ' ) ); ?><?php if(get_option('themes_fo2_view_time') && getPostViews(get_the_ID()));else{ ?><span><i class="icon-eye-open icon-large"></i> 围观<?php if(function_exists('the_views')) { the_views(); } ?></span><?php }?><span><i class="icon-comment-alt icon-large"></i> <?php comments_popup_link( __( 'Leave a comment', 'frontopen' ), __( '1 Comment', 'frontopen' ), __( '% Comments', 'frontopen' ) ); ?></span></aside>

loop-single.php(原文件第11行) :

<span><i class="icon-user icon-large"></i> <?php the_author_posts_link(); ?></span><?php printf( __( '<span><i class="icon-folder-open icon-large"></i> %2$s</span>', 'frontopen' ), 'i1', get_the_category_list( ', ' ) ); ?><span><i class="icon-eye-open icon-large"></i> 围观<i id="number"><?php if(function_exists('the_views')) { the_views(); } ?></i></span><span><i class="icon-comment-alt icon-large"></i> <?php comments_popup_link( __( 'Leave a comment', 'frontopen' ), __( '1 Comment', 'frontopen' ), __( '% Comments', 'frontopen' ) ); ?></span><span><i class="icon-pencil icon-large"></i> 编辑日期:<time><?php the_modified_time('Y-m-d')?></time></span><span><i class="icon-zoom-in icon-large"></i> 字体:<a href="javascript:;" onclick="checkFontSize(18)">大</a> <a href="javascript:;" onclick="checkFontSize(16)">中</a> <a href="javascript:;" onclick="checkFontSize(14)">小</a></span>

代码修改完以后,在WP后台设置wp-postviews显示格式为:“%VIEW_COUNT%次”即可。


更新说明(2014.6.14):

关于围观次数不增加的bug已经在最新的主题1.4.04.19中修复了,可以直接下载最新主题:

百度网盘: http://pan.baidu.com/s/1sjtZYCt