码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-05-12 17:12:26      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:

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


第一种案例演示:

技术分享




技术分享


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

技术分享


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

标签:

原文地址:http://blog.csdn.net/haoyunyun888/article/details/51364591

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!