• Downloading from our site will require you to have a paid membership. Upgrade to a Premium Membership from 10$ a month today!

    Dont forget read our Rules! Also anyone caught Sharing this content will be banned. By using this site you are agreeing to our rules so read them. Saying I did not know is simply not an excuse! You have been warned.

Share code smart search bằng từ khóa trong bài viết cho johncms

Admin

Well-Known Member
Staff member
Administrator
Share code Smart Search bằng từ khóa trong bài viết cho JohnCMS VN

Đoạn code này dùng để tự động gắn thêm link search vào các từ khóa có trong bài viết.

Demo http://xpro.asia
Khi bạn gõ johncms vn vào bài viết, nó sẽ tự động gắn link search vào từ đó.
johncms vn

Mở \incfiles\classes\bbcode.php
Thêm đoạn code sau vào:
PHP:
<?php
private static function smart_search($var)
{
$key = '/s(tu khoa 1|tu khoa 2|..tu khoa n)s/i';
$key = htmlentities($key, ENT_QUOTES, 'UTF-8');
return preg_replace($key, ' <a href="'.self::$system_set['homeurl'].'/forum/search.php?search=$1" title="Search: $1" target="_blank">$1</a> ', $var);
}
?>
Vị trí thêm tốt nhất là phía trên dấu } cuối cùng của file bbcode.php

Bạn có thể thêm bao nhiêu từ khóa tùy thích, mỗi từ khóa cách nhau bởi dấu |
Ký tự \s ở đầu và cuối, có ý nghĩa là trước và sau từ khóa phải là khoản trắng. nếu bạn không thích có thể bỏ.
Hãy cẩn thận khi dùng code này vì nó có thể gây xung đột với code url của JohnCMS. Chức năng khắc phục xung đột có trong bộ mã nguồn JohnCMS VN của Hoang Nhan Pro nhé.

Tìm đến
public static function tags($var)
{
Thêm vào bên trong function đó 1 dòng sau:
$var = self::smart_search($var);
Nguồn: XPRO
 

Facebook Comments

Similar threads

New posts New threads New resources

Back
Top