How to add a keyword table _php technique similar to PHPCMS 2008 in Phpcms V9

Source: Internet
Author: User
Tags keyword list
Recently used Phpcms V9 two times to develop a person site, before using 2008 has a more comfortable keyword all display function, and v9 added keyword list function to the search, if the search for a keyword will automatically generate an increase to the Search_keyword table, This is not very like v9 search function, I think the general will be used less, and we add the article when the keyword is actually separated, why to superfluous, in fact, the change is also relatively simple

Add a keyword_ext_model.class.php to the Model folder. Keyword_model actually exists in the Model folder, do not know why there is no keyword this table?

so do not in this basically increase, perhaps the future model will be used
Copy Code code as follows:

<?php
Defined (' In_phpcms ') or exit (' No permission resources ');
Pc_base::load_sys_class (' model ', ', ', 0);
Class Keyword_ext_model extends Model {
Public $table _name = ';
Public Function __construct () {
$this->db_config = pc_base::load_config (' database ');
$this->db_setting = ' default ';
$this->table_name = ' keyword_ext ';
Parent::__construct ();
}
}
?>

then create a table
Copy Code code as follows:

CREATE TABLE ' T_v9_keyword_ext ' (
' TagID ' smallint (5) unsigned not NULL auto_increment,
' Tag ' char (not NULL),
' Style ' char (5) Not NULL,
' Usetimes ' smallint (5) unsigned not NULL DEFAULT ' 0 ',
' Lastusetime ' int (a) unsigned not NULL DEFAULT ' 0 ',
' Hits ' Mediumint (8) unsigned not NULL DEFAULT ' 0 ',
' Lasthittime ' int (a) unsigned not NULL DEFAULT ' 0 ',
' Listorder ' tinyint (3) unsigned not NULL DEFAULT ' 0 ',
' ModelID ' smallint (6) DEFAULT ' 0 ',
PRIMARY KEY (' TagID '),
UNIQUE KEY ' tag ' (' tag '),
KEY ' usetimes ' (' usetimes ', ' Listorder '),
KEY ' hits ' (' Hits ', ' Listorder ')
) Engine=myisam auto_increment=2 DEFAULT Charset=utf8;

The final step is to add a input.inc.php to the Phpcms/modules/content/fields/keyword.
Copy Code code as follows:

function tags ($field, $value)
{
if (! $value) return ";
if (Strpos ($value, ', '))
{
$s = ', ';
}
Else
{
$s = ', ';
}

$keywords = Isset ($s)? Array_unique (Array_filter (Explode ($s, $value)): Array ($value);
$keyword _db = Pc_base::load_model (' Keyword_ext_model ');

foreach ($keywords as $tag)
{
$tag = Trim ($tag);
$keyword _db->delete (Array ("tag" => $tag, "ModelID" => $this->modelid));
$c = $this->db->count ("keywords like '%". $tag. " %'");
$keyword _db->insert (Array ("ModelID" => $this->modelid, "tag" => $tag, "Usetimes" => $c, "lastusetime" = >sys_time), false,true);
}

Return implode ($s, $keywords);
}

So in the article added keyword, will automatically increase to keyword_ext in a, call the whole station tags when directly to the table on the line. Please clear the total station cache first, otherwise you will not see the effect after modification.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.