KIẾN THỨC WEBSITE
Loại bỏ alias chuyên mục khỏi link bài viết trong module News

domain.com/news/<alias-category>/<alias-detail>-<id>.html
Bài viết này sẽ hướng dẫn các bạn loại bỏ <alias-category> khỏi link, nếu bạn chọn tính năng loại bỏ tên module news khỏi url thì link chi tiết sẽ rất gọn gàng.Chúng ta cùng bắt đầu nhé!
1. Xử lý $op
Mở file: modules\news\functions.phpTìm:
if ($count_op > 1 or $catid > 0) {
thay bằng:$array_page = explode('-', $array_op[0]); $id = intval(end($array_page)); $number = strlen($id) + 1; $alias_url = substr($array_op[0], 0, -$number); if ($id > 0 and $alias_url != '' and $alias_url != 'page') { $_row = $db->query('SELECT * FROM ' . NV_PREFIXLANG . '_' . $module_data . '_rows WHERE id = ' . $id)->fetch(); if (!empty($_row) and isset($global_array_cat[$_row['catid']])) { $catid = $_row['catid']; $op = 'detail'; } } elseif ($count_op > 1 or $catid > 0) {
2. Thêm link_detail cho $global_array_cat
Cũng trong file: modules\news\functions.phpTìm đoạn: (Line 34)
$global_array_cat[$l['catid']]['link'] = NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=' . $l['alias'];
Thêm bên dưới:$global_array_cat[$l['catid']]['link_detail'] = NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=';
3. Thay thế link chi tiết bài viết
Mở file: modules\news\funcs\detail.phpTìm đoạn:
$base_url = NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=' . $global_array_cat[$news_contents['catid']]['alias'] . '/' . $news_contents['alias'] . '-' . $news_contents['id'] . $global_config['rewrite_exturl'];
Thay bằng:$base_url = NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=' . $news_contents['alias'] . '-' . $news_contents['id'] . $global_config['rewrite_exturl'];
4. Xử lý link detail trong các file liên quan
- Mở file: modules\news\funcs\main.phpTìm và thay thế tất cả các đoạn như sau:
$global_array_cat[$item['catid']]['link'] . '/' . $item['alias']
thay bằng:$global_array_cat[$item['catid']]['link_detail'] . $item['alias']
Tìm và thay thế tất cả các đoạn như sau:
$array_cat_i['link'] . '/' . $item['alias']
thay bằng:$array_cat_i['link_detail'] . $item['alias']
- Mở file: modules\news\funcs\viewcat.php
Tìm và thay thế tất cả các đoạn như sau:
$global_array_cat[$item['catid']]['link'] . '/' . $item['alias']
thay bằng:$global_array_cat[$item['catid']]['link_detail'] . $item['alias']
- Mở file: modules\news\blocks\global.block_news_cat.php
Tìm:
$module_array_cat[$l['catid']]['alias'] . '/' . $l['alias']
thay bằng:$l['alias']
- Mở file: modules\news\blocks\global.block_tophits.php
Tim:
$module_array_cat[$catid]['alias'] . '/' . $alias
thay bằng:$alias
- Mở file: modules\news\blocks\module.block_news.php
Tìm:
$module_array_cat[$catid]['alias'] . '/' . $alias
thay bằng:$alias
Vậy là hoàn thành, chúc bạn thành công nhé!
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