详情页

ECSHOP给分类添加代表图

时间:2024年02月04日

编辑:佚名

ecshop的模板有很多不完善的地方,比如添加商品分类的时无法添加分类代表图,不能实现我们想要的效果,那么该如解决呢?
其实,我们只需要增加少量的代码就可以实现此功能。
1、修改/admin/template/category_info.html
复制代码
<tr>
<td>{$lang.cat_img}:</td>
<td>
<input name=”cat_img” size=”35″ type=”file” />
{if $cat_info.category_img}
<img src=”/{$cat_info.category_img}” border=”0″ alt=”" />
{/if}
</td>
</tr>
复制代码
2.修改/languages/zh_cn/admin/category.php
增加一个语言配置项
$_LANG['cat_img'] = ‘分类代表图片80*134′;
3.修改/admin/category.php 服务器添加上传图片的代码
在 require(dirname(__FILE__) . ‘/includes/init.php’);下一行
引入       cls_image.php图片上传类
include_once(ROOT_PATH . ‘includes/cls_image.php’);
-----------------------------------------------------------------------------------
在     if ($_REQUEST['act'] == ‘insert’){     下面增加代码
/* 二次开发追加 分类代表图片 */
$image = new cls_image();
$cat['category_img'] = $image->upload_image($_FILES['cat_img']);
-----------------------------------------------------------------------------------
在         if ($_REQUEST['act'] == ‘update’){         下面增加代码
/* 二次开发追加分类代表图片 */
$image = new cls_image();
$image = $image->upload_image($_FILES['cat_img']);
if(!empty($image)){
$cat['category_img'] = $image;
}
4.接下来,上传完点编辑的时候我们还要显示刚上传的图片,那么需要修改
/includes/lib_common.php里的function cat_list( 函数
在250行附近的$sql变量构造的时候追加一个category_img字段
$sql = “SELECT c.cat_id, c.cat_name, c.measure_unit, c.parent_id, c.is_show, c.show_in_nav, c.grade, c.sort_order, COUNT(s.cat_id) AS has_children,c.category_img “.
5.别忘记给xxx_category表增加一个varchar类型的category_img字段,用来存储上传的图片路径字符串
下面来说一下前台怎么显示,找取根目下的category.php文件。找到代码
复制代码
function get_cat_info($cat_id)
{
return $GLOBALS['db']->getRow(‘SELECT cat_name,category_img, keywords, cat_desc, style, grade, filter_attr, parent_id FROM ‘ . $GLOBALS['ecs']->table(‘category’) .
” WHERE cat_id = ‘$cat_id’”);
}
复制代码
加上 category_img。
再找到代码
复制代码
if (!empty($cat))
{
$smarty->assign(‘keywords’, htmlspecialchars($cat['keywords']));
$smarty->assign(‘description’, htmlspecialchars($cat['cat_desc']));
$smarty->assign(‘cat_style’, htmlspecialchars($cat['style']));
$smarty->assign(‘catname’, htmlspecialchars($cat['cat_name']));//自己加的
$smarty->assign(‘categoryimg’, htmlspecialchars($cat['category_img']));//自己加的
}
复制代码
这样在category.dwt模板文件里用{$categoryimg}就可以调用了。
相关文章
猜你需要