現時XOOPS系統預設的評論區塊只提供一個,將不同模組的最新評論匯集在一起,依發表時間的先後來排序。如果使用帶評論功能的模組不多,基本上一個評論區塊已足夠使用。
不過鑑於目前有人對獨立評論區塊的需求,為此寫一篇詳細教學,讓使用者去增設多個評論區塊。
目前預設評論區塊裡的表格分為圖示、標題、模組名稱、發表者和發表時間共五欄,當增設多個評論區塊後,由於可在區塊標題上標示模組名稱,表格裡頭的模組名稱欄位就變得多餘了,因此在進行區塊複製之前,先將模組名稱欄位的代碼去掉。
以下是/modules/system/templates/blocks/system_block_comments.html 裡的評論區塊代碼,橘字部份是模組名稱欄,可以將它刪除或加上如下綠色地方將之註解掉。
接下來建立新檔案,假設這是給新聞模組用的評論區塊,可以將它命名為system_block_comments_news.html。打開新建的檔案,將 system_block_comments.html 裡面代碼全複製到 system_block_comments_news.html 裡。
打開 /modules/system/xoops_version.php,將下圖的「1」複製到「2」位置
然後將「2」裡每一行的數值[10 ]改為[13],與上方小綠框裡的數值[12]成為連號。
將上面綠色檔名改為system_block_comments_news.html,再將上面橘色一行的 _MI_SYSTEM_BNAME11改為_MI_SYSTEM_BNAME14,並在 /modules/system/language/選用的語言/modinfo.php下第24行的 _MI_SYSTEM_BNAME13 後面加入如下
或是直接在原來的檔案下將它改成如下帶引號的中文也可。
接下來打開 /modules/system/blocks/system_blocks.php,將大約361行位置註解掉(見下面綠色雙斜槓),並在下一行加入如下綠色的一行:
接下來給每個區塊指定評論模組名稱,例如 /modules/system/templates/blocks/system_block_comments_news.html 這個檔是給新聞模組的,那就在裡面加上橘字smarty語法如下
上面橘字smarty語法中的紅字為模組名稱;另外預設的 /modules/system/templates/blocks/system_block_comments.html 這個檔,可以依樣畫葫蘆,加入如上的另一個模組名稱的smarty。
到後台更新system模組後,就可以到區塊管理去進行多個評論區塊的設定了。
不過鑑於目前有人對獨立評論區塊的需求,為此寫一篇詳細教學,讓使用者去增設多個評論區塊。
目前預設評論區塊裡的表格分為圖示、標題、模組名稱、發表者和發表時間共五欄,當增設多個評論區塊後,由於可在區塊標題上標示模組名稱,表格裡頭的模組名稱欄位就變得多餘了,因此在進行區塊複製之前,先將模組名稱欄位的代碼去掉。
以下是/modules/system/templates/blocks/system_block_comments.html 裡的評論區塊代碼,橘字部份是模組名稱欄,可以將它刪除或加上如下綠色地方將之註解掉。
![]()
![]()
<table width="100%" cellspacing="1" class="outer">
<{foreach item=comment from=$block.comments}>
<tr class="<{cycle values="even,odd"}>">
<td align="center"><img src="<{$xoops_url}>/images/subject/<{$comment.icon}>" alt="" /></td>
<td><{$comment.title}></td>
<{* <td align="center"><{$comment.module}></td> *}>
<td align="center"><{$comment.poster}></td>
<td align="right"><{$comment.time}></td>
</tr>
<{/foreach}>
</table>
接下來建立新檔案,假設這是給新聞模組用的評論區塊,可以將它命名為system_block_comments_news.html。打開新建的檔案,將 system_block_comments.html 裡面代碼全複製到 system_block_comments_news.html 裡。
打開 /modules/system/xoops_version.php,將下圖的「1」複製到「2」位置
然後將「2」裡每一行的數值[10 ]改為[13],與上方小綠框裡的數值[12]成為連號。
![]()
![]()
$modversion['blocks'][13]['file'] = "system_blocks.php"; $modversion['blocks'][13]['name'] = _MI_SYSTEM_BNAME11; $modversion['blocks'][13]['description'] = "Shows most recent comments"; $modversion['blocks'][13]['show_func'] = "b_system_comments_show"; $modversion['blocks'][13]['options'] = "10"; $modversion['blocks'][13]['edit_func'] = "b_system_comments_edit"; $modversion['blocks'][13]['template'] = 'system_block_comments.html';
將上面綠色檔名改為system_block_comments_news.html,再將上面橘色一行的 _MI_SYSTEM_BNAME11改為_MI_SYSTEM_BNAME14,並在 /modules/system/language/選用的語言/modinfo.php下第24行的 _MI_SYSTEM_BNAME13 後面加入如下
![]()
![]()
define('_MI_SYSTEM_BNAME13', "網站佈景");
define('_MI_SYSTEM_BNAME14', "這是區塊名稱");
或是直接在原來的檔案下將它改成如下帶引號的中文也可。
![]()
![]()
$modversion['blocks'][13]['file'] = "system_blocks.php";
$modversion['blocks'][13]['name'] ="這是區塊名稱例如命名為新聞評論";
$modversion['blocks'][13]['description'] = "Shows most recent comments";
$modversion['blocks'][13]['show_func'] = "b_system_comments_show";
$modversion['blocks'][13]['options'] = "10";
$modversion['blocks'][13]['edit_func'] = "b_system_comments_edit";
$modversion['blocks'][13]['template'] = 'system_block_comments_news.html';
接下來打開 /modules/system/blocks/system_blocks.php,將大約361行位置註解掉(見下面綠色雙斜槓),並在下一行加入如下綠色的一行:
![]()
![]()
// Check modules permissions
$comments = $comment_handler->getObjects($criteria, true);
$member_handler =& xoops_gethandler('member');
$module_handler =& xoops_gethandler('module');
$modules = $module_handler->getObjects(new Criteria('hascomments', 1), true);
$comment_config = array();
foreach (array_keys($comments) as $i) {
$mid = $comments[$i]->getVar('com_modid');
//$com['module'] = '<a href="'.XOOPS_URL.'/modules/'.$modules[$mid]->getVar('dirname').'/">'.$modules[$mid]->getVar('name').'</a>';
$com['module'] = $modules[$mid]->getVar('dirname');
if (!isset($comment_config[$mid])) {
$comment_config[$mid] = $modules[$mid]->getInfo('comments');
}
$com['id'] = $i;
$com['title'] = '<a href="'.XOOPS_URL.'/modules/'.$modules[$mid]->getVar('dirname').'/'.$comment_config[$mid]['pageName'].'?'.$comment_config[$mid]['itemName'].'='.$comments[$i]->getVar('com_itemid').'&com_id='.$i.'&com_rootid='.$comments[$i]->getVar('com_rootid').'&'.htmlspecialchars($comments[$i]->getVar('com_exparams')).'#comment'.$i.'">'.$comments[$i]->getVar('com_title').'</a>';
接下來給每個區塊指定評論模組名稱,例如 /modules/system/templates/blocks/system_block_comments_news.html 這個檔是給新聞模組的,那就在裡面加上橘字smarty語法如下
![]()
![]()
<table width="100%" cellspacing="1" class="outer">
<{foreach item=comment from=$block.comments}>
<{if $comment.module eq news}>
<tr class="<{cycle values="even,odd"}>">
<td align="center"><img src="<{$xoops_url}>/images/subject/<{$comment.icon}>" alt="" /></td>
<td><{$comment.title}></td>
<{* <td align="center"><{$comment.module}></td> *}>
<td align="center"><{$comment.poster}></td>
<td align="right"><{$comment.time}></td>
</tr>
<{/if}>
<{/foreach}>
</table>
上面橘字smarty語法中的紅字為模組名稱;另外預設的 /modules/system/templates/blocks/system_block_comments.html 這個檔,可以依樣畫葫蘆,加入如上的另一個模組名稱的smarty。
到後台更新system模組後,就可以到區塊管理去進行多個評論區塊的設定了。