iTheme2 使用WP-PostViews

本文共被喵星人侦察过6,293次。。。

很久以前看上的这款iTheme2主题,一开始换用了一下,结果发现WP-PostViews插件不能显示点击结果。。。虽然这个小站点击量不大,但是我还是希望能够显示出来每个文章的点击数。再加上当时时间不多,我就暂时把iTheme2主题禁用了,换用得iStudio。

今天配置WordPress的时候突然又看见了这个主题,启用以后发现还是这么喜欢这个主题,真心的很漂亮并且也有很多的功能。美中不足的还是:WP-PostViews插件能安装,能计数,就是不能在页面上显示结果。。。不过这难不倒懒猫,经过好几分钟的摸索,我终于成功把这个问题解决了。

解决的方法其实很简单,就是手动吧需要的函数插入主题文件中就可以了。WP-Postviews可以在任意的地方调用统计结果,只需要插入这样一行代码

<?php if(function_exists('the_views')) { the_views(); } ?>

不过说的很轻松,但是调整显示的位置是一件很麻烦的事情,尤其是在PHP文件中,又不能所见即所得,我就只能一行一行代码之间换,看看插在哪里能有稍微好点的效果。。。经过不懈的努力,终于弄的比较满意了,赶紧Mark+分享出来,嘿嘿。。。

首先是首页的统计信息,编辑iTheme2的 index.php文件,找到这样的几行


<!-- loops-wrapper -->
 <div class="loops-wrapper <?php echo $post_layout; ?>">

<?php while (have_posts()) : the_post(); ?>
<?php if(is_search()): ?>
 <?php get_template_part( 'includes/loop','search'); ?>
 <?php else: ?>
 <?php get_template_part( 'includes/loop','index'); ?>
 <?php endif; ?>

 <?php endwhile; ?>

 </div>
 <!-- /loops-wrapper -->

在中间加入PostView所需要的一行,变成这样:


<!-- loops-wrapper -->
 <div class="loops-wrapper <?php echo $post_layout; ?>">

<?php while (have_posts()) : the_post(); ?>
 <?php if(function_exists('the_views')) { the_views(); } ?>
 <?php if(is_search()): ?>
 <?php get_template_part( 'includes/loop','search'); ?>
 <?php else: ?>
 <?php get_template_part( 'includes/loop','index'); ?>
 <?php endif; ?>

 <?php endwhile; ?>

 </div>
 <!-- /loops-wrapper -->

然后保存文件,首页就算改好了。具体效果可以[button link=”http://iLazyCat.com” target=”_blank” ]看这里[/button]。这样就可以在首页的每个文章标题上面看到统计结果。

接下来是文章页面。编辑single.php,找到这几行:


<?php $post_image_width = themify_get('image_width'); ?>
 <?php $post_image_height = themify_get('image_height'); ?>
 <?php

 ///////////////////////////////////////////
 // Setting image width, height
 ///////////////////////////////////////////

修改一下,成这样


<?php $post_image_width = themify_get('image_width'); ?>
<?php $post_image_height = themify_get('image_height'); ?>
<?php if(function_exists('the_views')) { the_views(); } ?>
<?php

///////////////////////////////////////////
// Setting image width, height
///////////////////////////////////////////

效果可以[button link=”http://ilazycat.com/posts/2012/10/itheme2-enable-postviews.html”  target=”_blank”]看这里[/button]

然后是页面的显示。修改page.php,找下面几行


<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
 <?php global $post_query_category, $post_layout, $page_title, $hide_image, $hide_title, $unlink_title, $unlink_image, $hide_meta, $hide_date, $display_content; ?>

改为


<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php if(function_exists('the_views')) { the_views(); } ?>
 <?php global $post_query_category, $post_layout, $page_title, $hide_image, $hide_title, $unlink_title, $unlink_image, $hide_meta, $hide_date, $display_content; ?>

然后保存文件就可以了,页面的效果可以[button link=”http://ilazycat.com/chatbox” target=”_blank” ]看这里[/button]

嘻嘻,效果不错吧。。。其实我还是想让他显示在标题的下面,可是弄了半天都没弄好。要是有谁弄好了记得告诉懒猫哦~