【转】ZenCart:增加Popular Search
原文地址:http://www.fuyahui.com/zencart-add-popular-search.html
--------------------------------------------------------------------------
第一步执行数据库,代码如下
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; CREATE TABLE IF NOT EXISTS `customers_searches` (`search` varchar(255) NOT NULL DEFAULT '', `language_id` int(11) unsigned DEFAULT NULL,`freq` tinyint(3) unsigned DEFAULT '0',PRIMARY KEY (`search`) USING BTREE, KEY `lang` (`language_id`))ENGINE=MyISAM DEFAULT CHARSET=utf8;
第二步修改文件includes\modules\pages\advanced_search_result\header_php.php,也可以修改includes\application_bottom.php增加如下代码
/* 数据库中表customers_searches增加搜索次数和关键词*/ if ($_GET['keyword'] != '') { $search_count = $db->Execute("select freq from customers_searches where search = '". $_GET['keyword'] . "'"); if (!$search_count->RecordCount()) { $db->Execute("insert into customers_searches (search,language_id, freq) values ('". $_GET['keyword'] ."','". $_SESSION['languages_id'] ."',1)"); } else { $db->Execute("update customers_searches set freq = " . ($search_count->fields['freq']+1) . " where search = '". $_GET['keyword'] . "'"); }
第三步增加一个文件includes\modules\sideboxes\你自己的模板名称\popular_searches.php 代码如下 可以根据自己的需求进行修改。
<div id="information" style="width: 170px"> <div> <h3 id="informationHeading"><?php echo TEXT_BOX_POPULAR_SEARCHES;?></h3> </div> <div id="informationContent"> <ul style="margin: 0; padding: 0; list-style-type: none;"> <?php$popularSearches = $db->Execute('select search,freq from customers_searches limit 12'); $popularContent_i = 0;while(!$popularSearches->EOF){$popularContent =''; $popularContent .= '<a href="'.zen_href_link(FILENAME_ADVANCED_SEARCH_RESULT, 'keyword='.$popularSearches->fields['search'], 'NONSSL').'" _fcksavedurl="'. zen_href_link(FILENAME_ADVANCED_SEARCH_RESULT,'keyword='.$popularSearches->fields['search'], 'NONSSL').'">'; if($popularSearches->fields['freq'] >10){$popularContent .= '<strong style="color:red;">'; }$popularContent .= $popularSearches->fields['search']; if($popularSearches->fields['freq']>10){$popularContent .= '</strong>';}$popularContent .= '</a>'; if($popularContent_i < $popularSearches->RecordCount()){$popularContent .= ', '; $popularContent_i++;}echo $popularContent;$popularSearches->MoveNext();}?> </ul> </div> </div>
第四步在includes\languages\english.php中添加如下文字
define('TEXT_BOX_POPULAR_SEARCHES','Popular Searches');