- Tác giả: Garthbale site :
- Hướng dẫn:
+ Đầu tiên đối với data ta add thêm 1 cột "tags" trong table "forum" với:
Type là TEXT;
Collation là utf8_general_ci, còn lại bỏ qua rồi save lại như hình dưới.

+ Tiếp theo là file /forum/includes/nt.php: Khi post bài sẽ có ô điền tags
Tìm :$res_r = mysql_fetch_assoc($req_r);
Thêm vào sau :$tags = isset($_POST['tags']) ? functions::fixtags(mb_substr($_POST['tags'], 0, 100)) : '';
Tìm :`refid` = '$id',
Thêm sau :`tags` = '$tags',
Tìm :echo '<textarea rows="' . $set_user['field_h'] . '" name="msg">' . (isset($_POST['msg']) ? functions::checkout($_POST['msg']) : '') . '</textarea></p>' .
Thêm sau :'<p><b>Tags</b> <span class="gray">(cách nhau dấu ",")</span></p>' .
'<input type="text" maxlength="100" name="tags" value="' . $tags . '"/>' .
Save file nt.php lại.
+ Tiếp theo là file /forum/index.php
Tìm :$req = mysql_query("SELECT `text` FROM `forum` WHERE `id`= '" . $id . "'");
Thay thành :$req = mysql_query("SELECT `text`, `tags` FROM `forum` WHERE `id`='" . $id . "'");
Ngay dòng dưới có :$res = mysql_fetch_assoc($req);
Thêm đằng sau:$metatags = $res['tags'];
Thêm code sau vào chỗ thích hợp:/* hien thi tags */
if($metatags){
echo '<div class="bmenu"><u>Tags:</u> ';
$w_tag=substr_count($metatags,',')+1;
for($t=0; $t<$w_tag; $t++) {
$w_exp_label=explode(',',$metatags);
if (!empty($w_exp_label) ? ', ' : '') {
echo '<a href="search.php?search='.str_replace(' ','+',$w_exp_label[$t]).'" title="' . $w_exp_label[$t] . '">'.$w_exp_label[$t].'</a>, ';
} }
echo '</div>';
}
Xong! Rất đơn giản phải không nào :P
Trên đây là module tags cho JohnCMS do mình tự viết và có tham khảo một số bạn. Dựa vào code trên các bạn có thể đưa tagslên làm keyword hay decs... Có gì thắc mắc mình sẽ giúp đỡ nhiệt tình.
Chúc các bạn thành công!
Demo ảnh:


No comments:
Post a Comment