14.
XOOPS的評論功能

一、 加入評論功能(Comments)
- 若是想要在模組中套用評論功能,那麼必須設定以下項目:
//---評論---//
$modversion['hasComments'] = 1;
$modversion['comments']['pageName'] = 'view.php';
$modversion['comments']['itemName'] = 'honor_sn';
-
- (1) $modversion['hasComments'] = 1; //是否啟用評論功能?
- (2) $modversion['comments']['itemName'] = 'honor_sn'; //評論項目的唯一辨識欄位的名稱(給程式用的)
- (3) $modversion['comments']['pageName'] = 'view.php'; //要加入評論的頁面
- 接著把「評論檔」中的五個檔案複製到「模組根目錄」即tad_honor下。
- 在view.php的下方include....foot.php前加入一行:
include_once XOOPS_ROOT_PATH.'/include/comment_view.php';
include_once XOOPS_ROOT_PATH.'/footer.php';
?>
- 開啟「評論樣板檔語法.txt」,複製語法到樣版檔tad_honor_view_tpl.html中
<div style="text-align: center; padding: 3px; margin: 3px;">
<{$commentsnav}>
<{$lang_notice}>
</div>
<div style="margin: 3px; padding: 3px;">
<!-- start comments loop -->
<{if $comment_mode == "flat"}>
<{include file="db:system_comments_flat.html"}>
<{elseif $comment_mode == "thread"}>
<{include file="db:system_comments_thread.html"}>
<{elseif $comment_mode == "nest"}>
<{include file="db:system_comments_nest.html"}>
<{/if}>
<!-- end comments loop -->
</div>
- 到後台更新您的模組(為了重讀樣版及設定檔),就大功告成囉!
三、 修改評論畫面
- 替評論加上「$com_replytitle」回覆標題,及「$com_replytext」被回覆的內容。
- 這兩個變數的值,我們利用該文章編號「$com_itemid」直接撈出該文章的標題和內容即可。
- 修改comment_new.php
<?php
include '../../mainfile.php';
$com_itemid = isset($_GET['com_itemid']) ? intval($_GET['com_itemid']) : 0;
if ($com_itemid > 0) {
$sql="select `honor_students` , `honor_descript` from ".$xoopsDB->prefix("tad_honor")." where honor_sn='{$com_itemid}'";
$result=$xoopsDB->query($sql);
list($honor_students , $honor_descript) = $xoopsDB->fetchRow($result);
}
$com_replytitle = "RE:{$honor_students}榮獲{$honor_descript}";
$com_replytext = "";
include XOOPS_ROOT_PATH.'/include/comment_new.php';
?>
- 如此一來,人家在評論的時候就可以清楚知道,正在回覆的是哪一篇,也不用自己填上標題了。