添加栏目缩略图
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}就可以調用了。
轉載于:https://www.cnblogs.com/longhun/p/4476913.html
總結
- 上一篇: firefox加载不来
- 下一篇: Knockoutjs 实践入门 (2)