社會化評論系統,相信絕對大多數人都知道並且使用過。之前使用過暢言,友言,對著倆貨,不作過多評論,單純從外觀上,友言就已經遠遠遜色於暢言和多說,相關對比引數不再贅述,總之一句話,哪個好用,哪個好看用哪個。
多說總之載入速度方面和外觀方面都非常不錯,簡潔不羅嗦,總比暢言卡的一逼強。使用多說,註冊賬號之後,開始部署通用程式碼,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 過去的引數後臺顯示亂碼!