ecshop二次開發--熱詞搜尋且顯示
阿新 • • 發佈:2019-02-07
1.進入upload->themes->degault->library->page_header.lbi中搜索以下程式碼
{if $searchkeywords}
{$lang.hot_search} :
{foreach from=$searchkeywords item=val}
<a href="search.php?keywords={$val|escape:url}">{$val}</a>
{/foreach}
{/if}
2把搜尋到的程式碼替換為一下程式碼
{$lang.hot_search} : {if $searchkeywords} {foreach from=$searchkeywords item=val} <a href="search.php?keywords={$val|escape:url}">{$val}</a> {/foreach} {/if} // 資料庫ecs_keywords 表中的資料 {if $searchengine} {foreach from=$searchengine item=val} {foreach from=$val key=key item=v} <a href="search.php?keywords={$key|escape:url}">{$key}</a> {/foreach} {/foreach} {/if}
3.進入upload->admin->searchengie_stats.php複製一下程式碼
/* 時間引數 */ /* TODO: 時間需要改 */ if (isset($_POST) && !empty($_POST)) { $start_date = $_POST['start_date']; $end_date = $_POST['end_date']; } else { $start_date = local_date('Y-m-d', strtotime('-1 week')); $end_date = local_date('Y-m-d'); } /* ------------------------------------- */ /* --綜合流量 /* ------------------------------------- */ $max = 0; $general_xml = "<chart caption='$_LANG[tab_keywords]' shownames='1' showvalues='0' decimals='0' numberPrefix='' outCnvBaseFontSize='12' baseFontSize='12'>"; $sql = "SELECT keyword, count, searchengine ". " FROM " .$ecs->table('keywords'). " WHERE date >= '$start_date' AND date <= '" .$end_date. "'"; if (isset($_POST['filter'])) { $sql .= ' AND '. db_create_in($_POST['filter'], 'searchengine'); } $res = $db->query($sql); $search = array(); $searchengine = array(); $keyword = array(); while ($val = $db->fetchRow($res)) { $keyword[$val['keyword']] = 1; $searchengine[$val['searchengine']][$val['keyword']] = $val['count']; }
4.將你複製到的程式碼放入到upload->includes->lib_main.php後找到assign_template方法後,將你複製到的程式碼放到assign_template後
注意:第四步是我已經將第三部程式碼所整合在一起了,所以在這裡第三部你可以省下不用寫。
以下程式碼是我將我所複製的程式碼放到assign_template方法後的效果
function assign_template($ctype = '', $catlist = array())
{
global $smarty;
$smarty->assign('image_width', $GLOBALS['_CFG']['image_width']);
$smarty->assign('image_height', $GLOBALS['_CFG']['image_height']);
$smarty->assign('points_name', $GLOBALS['_CFG']['integral_name']);
$smarty->assign('qq', explode(',', $GLOBALS['_CFG']['qq']));
$smarty->assign('ww', explode(',', $GLOBALS['_CFG']['ww']));
$smarty->assign('ym', explode(',', $GLOBALS['_CFG']['ym']));
$smarty->assign('msn', explode(',', $GLOBALS['_CFG']['msn']));
$smarty->assign('skype', explode(',', $GLOBALS['_CFG']['skype']));
$smarty->assign('stats_code', $GLOBALS['_CFG']['stats_code']);
$smarty->assign('copyright', sprintf($GLOBALS['_LANG']['copyright'], date('Y'), $GLOBALS['_CFG']['shop_name']));
$smarty->assign('shop_name', $GLOBALS['_CFG']['shop_name']);
$smarty->assign('service_email', $GLOBALS['_CFG']['service_email']);
$smarty->assign('service_phone', $GLOBALS['_CFG']['service_phone']);
$smarty->assign('shop_address', $GLOBALS['_CFG']['shop_address']);
$smarty->assign('licensed', license_info());
$smarty->assign('ecs_version', VERSION);
$smarty->assign('icp_number', $GLOBALS['_CFG']['icp_number']);
$smarty->assign('username', !empty($_SESSION['user_name']) ? $_SESSION['user_name'] : '');
$smarty->assign('category_list', cat_list(0, 0, true, 2, false));
$smarty->assign('catalog_list', cat_list(0, 0, false, 1, false));
$smarty->assign('navigator_list', get_navigator($ctype, $catlist)); //自定義導航欄
if (!empty($GLOBALS['_CFG']['search_keywords']))
{
$searchkeywords = explode(',', trim($GLOBALS['_CFG']['search_keywords']));
}
else
{
$searchkeywords = array();
}
$smarty->assign('searchkeywords', $searchkeywords);
/* 時間引數 */
/* TODO: 時間需要改 */
if (isset($_POST) && !empty($_POST))
{
$start_date = $_POST['start_date'];
$end_date = $_POST['end_date'];
}
else
{
$start_date = local_date('Y-m-d', strtotime('-1 week'));
$end_date = local_date('Y-m-d');
}
/* ------------------------------------- */
/* --綜合流量
/* ------------------------------------- */
$max = 0;
//$general_xml = "<chart caption='$_LANG[tab_keywords]' shownames='1' showvalues='0' decimals='0' numberPrefix='' outCnvBaseFontSize='12' baseFontSize='12'>";
$sql = "SELECT keyword, count, searchengine ".
" FROM " .$GLOBALS['ecs']->table('keywords').
" WHERE date >= '$start_date' AND date <= '" .$end_date. "'order by count desc limit 5";
if (isset($_POST['filter']))
{
$sql .= ' AND '. db_create_in($_POST['filter'], 'searchengine');
}
$res = $GLOBALS['db']->query($sql);
$search = array();
$searchengine = array();
$keyword = array();
while ($val = $GLOBALS['db']->fetchRow($res))
{
$keyword[$val['keyword']] = 1;
$searchengine[$val['searchengine']][$val['keyword']] = $val['count'];
}
$smarty->assign("searchengine",$searchengine);
}
5.這樣所做的搜尋就到此完畢了。
第一種案例演示:
第二種案例演示:(直接從後臺進行新增,你所想要搜尋的詞語)