![[NukeViet CMS] Loại bỏ alias chuyên mục khỏi link bài viết trong module News](/uploads/blog/2021_05/loai-bo-alias-chuyen-muc.png.webp)
[NukeViet CMS] Loại bỏ alias chuyên mục khỏi link bài viết trong module News
Cấu trúc link chi tiết bài viết của module News trên CMS NukeViet mặc định có dạng rất dài. Bài viết này sẽ hướng dẫn các bạn loại bỏ alias chuyên mục 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.
Mục lục
Cấu trúc link chi tiết bài viết của module News trên CMS NukeViet mặc định có dạng
Chúng ta cùng bắt đầu nhé!1. Xử lý
Mở file: modules\news\functions.php
Tìm:2. Thêm link_detail cho
Cũng trong file: modules\news\functions.php
Tìm đoạn: (Line 34)
Mở file: modules\news\funcs\detail.php
Tìm đoạn:
- Mở file: modules\news\funcs\main.php
Tìm và thay thế tất cả các đoạn như sau:
Tìm và thay thế tất cả các đoạn như sau:
- Mở file: modules\news\funcs\viewcat.php
Tìm và thay thế tất cả các đoạn như sau:
- Mở file: modules\news\blocks\global.block_news_cat.php
Tìm:
- Mở file: modules\news\blocks\global.block_tophits.php
Tim:
- Mở file: modules\news\blocks\module.block_news.php
Tìm:
Vậy là hoàn thành, chúc bạn thành công nhé!
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é!
Tham khảo thêm một số bài viết hướng dẫn về NukeViet khác:
Từ khóa được tìm kiếm nhiều nhất: Loại bỏ alias chuyên mục khỏi link bài viết trong module News
Nguồn tin: vuta.vn
Chú ý: Việc đăng lại bài viết trên ở website hoặc các phương tiện truyền thông khác mà không ghi rõ nguồn https://vuta.vn là vi phạm bản quyền.
Tác giả: Huỳnh Quốc Đạt