打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
使用Cookie方法实现最近浏览过的信息调用_帝国cms插件_为帝国cms模板用户提供建站...

使用Cookie方法实现最近浏览过的信息调用

 调用最近浏览过的商品或信息

把userfun.php文件复制到e/class/userfun.php覆盖原来的文件
把ShowInfo.php文件复制到e/action/ShowInfo.php覆盖原来的文件

栏目
在模板管理-标签-标签管理-增加标签,输入以下信息

标签名:最近浏览过的
标签符号:darkcircleming
函数名:darkcircleming
标签格式:[darkcircleming]COOKIE变量名,标题截取数[/darkcircleming]

在添加栏目的时候,在生成选项选择内容页模式为:动态页面

以下为userfun.php的内容
<?
//获得当前格林威治时间的时间戳
function gmtime()
{
    return (time() - date('Z'));
}

//记录最近浏览
function recently_viewed($id,$tbname){

   if (!empty($_COOKIE[$tbname]))
   {
       $history = explode(',', $_COOKIE[$tbname]);
       array_unshift($history, $id);
       $history = array_unique($history);

       while (count($history) > 10)
       {
           array_pop($history);
       }

       setcookie($tbname, implode(',', $history), gmtime() + 3600 * 24 * 30);
   }
   else
   {
       setcookie($tbname, $id, gmtime() + 3600 * 24 * 30);
   }
}

//调用最新浏览过的信息
function darkcircleming($table,$strlen){
    global $empire,$public_r,$fun_r,$dbtbpre;
       
        $where = db_create_in($_COOKIE[$table], 'id');
         $sql = $empire->query("select title,classid,id from {$dbtbpre}ecms_{$table} where $where order by istop desc,newstime desc,id desc limit 7");
        while($r=$empire->fetch($sql))
        {
           $title=sub($r[title],0,$strlen,false);
           $title=DoTitleFont($r[titlefont],$title);
           $titleurl=sys_ReturnBqTitleLink($r);
           $list .= "<li>·<a href="".$titleurl."" target="_blank" title="".$r[title]."">".$title."</a></li>";
        }
    echo "<ul>".$list."</ul>";
}

/**
* 创建像这样的查询: "IN('a','b')";
*
* @access   public
* @param    mix      $item_list      列表数组或字符串
* @param    string   $field_name     字段名称
*
* @return   void
*/
function db_create_in($item_list, $field_name = '')
{
    if (empty($item_list))
    {
        return $field_name . " IN ('') ";
    }
    else
    {
        if (!is_array($item_list))
        {
            $item_list = explode(',', $item_list);
        }
        $item_list = array_unique($item_list);
        $item_list_tmp = '';
        foreach ($item_list AS $item)
        {
            if ($item !== '')
            {
                $item_list_tmp .= $item_list_tmp ? ",'$item'" : "'$item'";
            }
        }
        if (empty($item_list_tmp))
        {
            return $field_name . " IN ('') ";
        }
        else
        {
            return $field_name . ' IN (' . $item_list_tmp . ') ';
        }
    }
}
?>

ShowInfo.php 为动态内容页
在282行增加
recently_viewed($add[id],$class_r[$add[classid]][tbname]);
 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
免费的PHP的CMS系统-PHP,CMS系统,免费CMS,网站-网站建设
APP接口设计安全问题
深入PrestaShop核心开发
Python合并两个列表的方法
dede cms去版权
【强烈推荐】免费大量中医资源下载
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服