社會化評論系統,相信絕對大多數人都知道並且使用過。之前使用過暢言,友言,對着倆貨,不作過多評論,單純從外觀上,友言就已經遠遠遜色於暢言和多説,相關對比參數不再贅述,總之一句話,哪個好用,哪個好看用哪個。
多説總之加載速度方面和外觀方面都非常不錯,簡潔不羅嗦,總比暢言卡的一逼強。使用多説,註冊賬號之後,開始部署通用代碼,WordPress 構建的站點原則上儘量不使用多説的 wp 插件,你懂的。 woocommerce 插件構建的電子商務商品頁面中部署多説。
找到模板的 description.php 文件 (具體路徑:ext/woocommerce/templates/single-product/tabs/)
description.php 中在函數
<span style="font-family:Microsoft YaHei;font-size:14px;"><?php the_content(); ?></span>
商品詳情頁輸出之後去加載多説。
多説的通用代碼如下:
<!-- 多説評論框 start -->
<div data-thread-key="請將此處替換成文章在你的站點中的 ID" data-title="請替換成文章的標題" data-url="請替換成文章的網址"></div>
<!-- 多説評論框 end -->
<!-- 多説公共 JS 代碼 start (一個網頁只需插入一次) -->
<script type="text/javascript">
var duoshuoQuery = {short_name:"kejianet"};
(function() { var ds = document.createElement('script'); ds.type = 'text/javascript';ds.async = true; ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js'; ds.charset = 'UTF-8'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ds);
})();
</script>
<!-- 多説公共 JS 代碼 end -->
data-thread-key="請將此處替換成文章在你的站點中的 ID" data-title="請替換成文章的標題" data-url="請替換成文章的網址"
這三個參數是需要用户去用變量去替換的。如果不替換參數,單個頁面中的評論將不能區分顯示!
具體代碼如下:
<span style="font-family:Microsoft YaHei;font-size:14px;"><?php the_content(); ?>
<br/>
<!-- 多説評論框 start -->
<div data-thread-key="<?php the_ID(); ?>" data-title="<?php echo curPageTitle(); ?>" data-url="<?php echo curPageURL(); ?>" ></div>
<script type="text/javascript">
var duoshuoQuery = {short_name:"kejianet"};
(function() { var ds = document.createElement('script'); ds.type = 'text/javascript';ds.async = true; ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js'; ds.charset = 'UTF-8'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ds);
})();
</script>
<?php
//獲取當前頁面 URL
function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") { $pageURL .= "s"; } $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; } return $pageURL;
}
//獲取當前頁面標題
function curPageTitle()
{ $title = get_post(get_the_ID())->post_title; return $title;
} ?>
<!-- 多説評論框 end --></span>
三個變量即完成了配置。
多説後台則顯示如下:
最後一個問題:切記你加入多説通用代碼的頁面編碼必須是 UTF-8,否則 post 過去的參數後台顯示亂碼!