1.分类筛选
category.dwt 中添加的代码需要自己根据模板需要添加css,选中栏目的背景颜色设置下span标签的底色就可以了演示效果
步骤如下一、category.php中添加代码:
//当前二级分类
$smarty->assign('categories1', get_categories(get_parent($cat_id)));
$smarty->assign('parent_id', get_parent($cat_id));//顶级分类id
/*获取顶级id*/
function get_parent($value,$id='')
{
if($value!=0)
{
$sql = 'SELECT parent_id FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '$value'";
$res = $GLOBALS['db']->getOne($sql);
return get_parent($res,$value);
}
else
{
return $id;
}
}
/*提取二级分类*/
function get_categories($cat_id = 0)
{
if ($cat_id > 0)
{
$parent_id = $cat_id;
}
else
{
$parent_id = 0;
}
/*
判断当前分类中全是是否是底级分类,
如果是取出底级分类上级分类,
如果不是取当前分类及其下的子分类
*/
$sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$cat_id' AND is_show = 1 ";
if ($GLOBALS['db']->getOne($sql) || $parent_id == 0)
{
/* 获取当前分类及其子分类 */
$sql = 'SELECT a.cat_id, a.cat_name, a.sort_order AS parent_order, a.cat_id, a.is_show,' .
'b.cat_id AS child_id, b.cat_name AS child_name, b.sort_order AS child_order ' .
'FROM ' . $GLOBALS['ecs']->table('category') . ' AS a ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('category') . ' AS b ON b.parent_id = a.cat_id AND b.is_show = 1 ' .
"WHERE a.parent_id = '$parent_id' ORDER BY parent_order ASC, a.cat_id ASC, child_order ASC";
}
else
{
/* 获取当前分类及其父分类 */
$sql = 'SELECT a.cat_id, a.cat_name, b.cat_id AS child_id, b.cat_name AS child_name, b.sort_order, b.is_show ' .
'FROM ' . $GLOBALS['ecs']->table('category') . ' AS a ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('category') . ' AS b ON b.parent_id = a.cat_id AND b.is_show = 1 ' .
"WHERE b.parent_id = '$parent_id' ORDER BY sort_order ASC";
}
$res = $GLOBALS['db']->getAll($sql);
$cat_arr = array();
foreach ($res AS $row)
{
if ($row['is_show'])
{
$cat_arr[$row['cat_id']]['id'] = $row['cat_id'];
$cat_arr[$row['cat_id']]['name'] = $row['cat_name'];
$cat_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
if ($row['child_id'] != NULL)
{
$cat_arr[$row['cat_id']]['children'][$row['child_id']]['id'] = $row['child_id'];
$cat_arr[$row['cat_id']]['children'][$row['child_id']]['name'] = $row['child_name'];
$cat_arr[$row['cat_id']]['children'][$row['child_id']]['url'] = build_uri('category', array('cid' => $row['child_id']), $row['child_name']);
}
}
}
return $cat_arr;
}
二、category.dwt 中 合适的位置添加 代码:(这个需要注意,有的筛选是加载到lib文件里,自己根据自己的模板需求按位置添加)
?添加代码结果无效?,这是由于在category.php中添加代码的时候位置不对,多试几个位置,我是添加到78行。这个位置以上的代码是
/*------------------------------------------------------ */
//-- INPUT
/*------------------------------------------------------ */
/* 获得请求的分类 ID */
if (isset($_REQUEST['id']))
{
$cat_id = intval($_REQUEST['id']);
}
elseif (isset($_REQUEST['category']))
{
$cat_id = intval($_REQUEST['category']);
}
else
{
/* 如果分类ID为0,则返回首页 */
ecs_header("Location: ./\n");
exit;
}
可以对照一下
-----------------------------------
2.颜色筛选
牵涉到的修改文件
/admin/templates/goods_info.htm
/admin/goods.php
/goods.php
修改步骤:
1:后台运行sql语句,admin后台->左侧导航->数据库管理->SQL查询
运行下面的语句(只能运行一次,小心):
alter table ecs_goods add seo_title text not null
2:修改 admin/templates/goods_info.htm
在此文件的第44行后面,加上下面几行
自定义title
3:修改admin/goods.php
第765行
"is_on_sale, is_alone_sale, goods_desc, add_time, last_update, goods_type, rank_integral)" .
修改为:
"is_on_sale, is_alone_sale, goods_desc, add_time, last_update, goods_type, rank_integral,seo_title)" .
复制代码
第771行,
" '$_POST[goods_desc]', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$rank_integral')";
修改为
" '$_POST[goods_desc]', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$rank_integral','$_POST[seo_title]')";
第779行
"is_on_sale, is_alone_sale, goods_desc, add_time, last_update, goods_type, extension_code, rank_integral)" .
修改为:
"is_on_sale, is_alone_sale, goods_desc, add_time, last_update, goods_type, extension_code, rank_integral,seo_title)" .
第785行
" '$_POST[goods_desc]', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$code', '$rank_integral')";
修改为:
" '$_POST[goods_desc]', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$code', '$rank_integral','$_POST[seo_title]')";
第817行:
"promote_end_date = '$promote_end_date', ";
修改为:
"seo_title = '$_POST[seo_title]', ";```
4:修改/goods.php的第161行为:
$smarty->assign('page_title', trim($goods['seo_title'])?$goods['seo_title']:$position['title']); // 页面标题
清除缓存
测试:
编辑商品或添加商品 -> 自定义Title
完成
.