Mystique主题与WP-PostViews Plus插件的冲突问题
本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/program/mystique_postviews.html
今天升级了Mystique主题到1.72版,原来的那个Bug又出现了,会在页面的顶头显示一段代码,查看了源码,发现是WP-PostViews Plus的代码和Mystique主题冲突了,我们来看原始输出的HTML:
<body class="
<!-- Start Of Script Generated By WP-PostViews Plus -->
<script type="text/javascript">
/* <![CDATA[ */
jQuery.ajax({type:'GET',url:'http://www.penglixun.com/wp-content/plugins/wp-postviews-plus/postviews_plus.php',data:'todowppvp=&type=index&id=1',cache:false,dataType:'script'});
/* ]]> */
</script>
<!-- End Of Script Generated By WP-PostViews Plus -->
home blog col-2-right loggedin browser-chrome"> |
这不出问题才怪呢,正常的情况应该是
<!-- Start Of Script Generated By WP-PostViews Plus -->
<script type="text/javascript">
/* <![CDATA[ */
jQuery.ajax({type:'GET',url:'http://www.penglixun.com/wp-content/plugins/wp-postviews-plus/postviews_plus.php',data:'todowppvp=&type=index&id=1',cache:false,dataType:'script'});
/* ]]> */
</script>
<!-- End Of Script Generated By WP-PostViews Plus -->
<body class="home blog col-2-right loggedin browser-chrome"> |
或者
在上面。刨根问底,元凶指向mystique_body_class这个函数,发现在core.php文件中。
问题在哪呢?
// Special classes for BODY element when a single post if (is_single()): $postID = $wp_query->post->ID; the_post(); // Adds 'single' class and class with the post ID $c[] = 'single-post postid-' . $postID; ...... // And tada! return $print ? print($c) : $c; |
就是the_post()函数,调用the_post()时,WP-PostViews Plus的代码就被加入了,而body class= 已经输出了。
解决方法很简单,把the_post()转移到最后,就是print的下一行,这样就OK了。把这个函数里其他the_post()都删除,留一个在print的下一行就行。
博主你好。我用的是Emperors Theme主题,也和这个插件相冲突,麻烦指点一下如何修改。俺菜鸟一只。麻烦了。谢谢。
[回复]