KIẾN THỨC WEBSITE
Tự động tạo backlink từ khóa trong nội dung NukeViet qua thẻ tag

Cơ chế hoạt động
Dựa vào danh sách từ khóa (tag) của module, tìm trong nội dung tất cả các từ khóa có trong danh sách và thêm liên kết đến trang xem danh sách bài viết thuộc từ khóa cho từ khóa đóYêu cầu về module có thể tích hợp
- Module có sử dụng chức năng tag (Quản lý từ khóa)
- Một module có thể: news, shops, download
Hướng dẫn tích hợp cho module news (và các module ảo)
Mở modules/news/funcs/detail.php
Tìm
$contents = detail_theme($news_contents, $array_keyword, $related_new_array, $related_array, $topic_array, $content_comment);
Thêm bên trên$auto_link_config = array( 'auto_link' => 1, // 1: kích hoạt, 0: không kích hoạt 'auto_link_casesens' => 1, // 1: không phân biệt ký tự HOA/thường, 0: ngược lại 'auto_link_target' => '_blank', // phương án mở liên kết, xem thêm https://www.w3schools.com/tags/att_a_target.asp 'auto_link_limit' => 3, // số lượng từ khóa sẽ thay thế. VD nội dung có 10 từ khóa thì chỉ thay thế 3 từ đầu tiên 'auto_link_content' => $news_contents['bodyhtml'] // biến nội dung cần thay thế);if ($auto_link_config['auto_link']) { $reg_post = $auto_link_config['auto_link_casesens'] ? '/(?!(?:[^<\[]+[>\]]|[^>\]]+<\/a>))($content)/imsu' : '/(?!(?:[^<\[]+[>\]]|[^>\]]+<\/a>))($content)/msu'; $sql = 'SELECT keywords, alias FROM ' . NV_PREFIXLANG . '_' . $module_data . '_tags'; $array_keywords = $nv_Cache->db($sql, 'tid', $module_name); foreach ($array_keywords as $keyword) { $url = NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=' . $module_info['alias']['tag'] . '/' . $keyword['alias']; $regexp = str_replace('$content', $keyword['keywords'], $reg_post); $replace = '<a title="$1" href="$$$url$$$" ' . (! empty($keyword['auto_link_target']) ? 'target="' . $keyword['auto_link_target'] . '"' : '') . '>$1</a>'; $newtext = preg_replace($regexp, $replace, $auto_link_config['auto_link_content'], $auto_link_config['auto_link_limit']); if ($newtext != $keyword['keywords']) { $auto_link_config['auto_link_content']= str_replace('$$$url$$$', $url, $newtext); } } $news_contents['bodyhtml'] = $auto_link_config['auto_link_content'];}
Hướng dẫn tích hợp cho module Shops (và module ảo)
Mở modules/shops/funcs/detail.php
Tìm
$contents = detail_product($data_content, $data_unit, $data_others, $array_other_view, $content_comment, $compare_id, $popup, $idtemplate, $array_keyword);
Thêm bên trên$auto_link_config = array( 'auto_link' => 1, // 1: kích hoạt, 0: không kích hoạt 'auto_link_casesens' => 1, // 1: không phân biệt ký tự HOA/thường, 0: ngược lại 'auto_link_target' => '_blank', // phương án mở liên kết, xem thêm https://www.w3schools.com/tags/att_a_target.asp 'auto_link_limit' => 3, // số lượng từ khóa sẽ thay thế. VD nội dung có 10 từ khóa thì chỉ thay thế 3 từ đầu tiên 'auto_link_content' => $data_content[NV_LANG_DATA . '_bodytext'] // biến nội dung cần thay thế);if ($auto_link_config['auto_link']) { $reg_post = $auto_link_config['auto_link_casesens'] ? '/(?!(?:[^<\[]+[>\]]|[^>\]]+<\/a>))($content)/imsu' : '/(?!(?:[^<\[]+[>\]]|[^>\]]+<\/a>))($content)/msu'; $sql = 'SELECT keywords, alias FROM ' . $db_config['prefix'] . '_' . $module_data . '_tags_' . NV_LANG_DATA; $array_keywords = $nv_Cache->db($sql, 'tid', $module_name); foreach ($array_keywords as $keyword) { $url = NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=' . $module_info['alias']['tag'] . '/' . $keyword['alias']; $regexp = str_replace('$content', $keyword['keywords'], $reg_post); $replace = '<a title="$1" href="$$$url$$$" ' . (! empty($keyword['auto_link_target']) ? 'target="' . $keyword['auto_link_target'] . '"' : '') . '>$1</a>'; $newtext = preg_replace($regexp, $replace, $auto_link_config['auto_link_content'], $auto_link_config['auto_link_limit']); if ($newtext != $keyword['keywords']) { $auto_link_config['auto_link_content']= str_replace('$$$url$$$', $url, $newtext); } } $data_content[NV_LANG_DATA . '_bodytext'] = $auto_link_config['auto_link_content'];}
Tác giả bài viết: Trần Minh Tuấn

Vui lòng liên hệ để được tư vấn!
0903.177.877 - 0988 80 13 80 ĐĂNG KÝ NGAY
Những tin mới hơn
Những tin cũ hơn