您的位置:首页 > 运维架构

ecshop二次开发--热词搜索且显示

2016-10-21 16:26 399 查看
1.进入upload->themes->degault->library->page_header.lbi中搜索以下代码

[python]
view plain
copy





{if $searchkeywords}  
  
     {$lang.hot_search} :  
  
    {foreach from=$searchkeywords item=val}  
  
        <a href="search.php?keywords={$val|esc
4000
ape:url}">{$val}</a>  
  
    {/foreach}  
  
{/if}  

2把搜索到的代码替换为一下代码

[python]
view plain
copy





         {$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复制一下代码

[python]
view plain
copy

/* 时间参数 */  
/* 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方法后的效果

[python]
view plain
copy

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 "
ad9e
.  
            " 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.这样所做的搜索就到此完毕了。

第一种案例演示:





第二种案例演示:(直接从后台进行添加,你所想要搜索的词语)

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: