注:本教程使用的dedecms版本为:V5.7SP2 utf-8版。
一、向dede_arctype栏目数据表种添加图片字段typeimg通过 系统 - SQL命令行工具,输入下边代码,执行
alter table `dede_arctype` add `typeimg` varchar(200) NOT NULL default '';意思是在数据库表dede_arctype中添加一个typeimg字段,typeimg这个名字可以自定义命名。二、修改文件:
dede/catalog_add.php
dede/catalog_edit.php dede/templets/catalog_add.htm dede/templets/catalog_edit.htmPS:dede为默认后台文件夹 1)修改dede/catalog_add.php文件打开文件,开始查找在65行找到$queryTemplate = "INSERT INTO `#@__arctype`(reid,topid,sortrank,typename,将其替换为:$queryTemplate = "INSERT INTO `#@__arctype`(reid,topid,sortrank,typename,typeimg,在67行找到VALUES('~reid~','~topid~','~rank~','~typename~',将其替换为:VALUES('~reid~','~topid~','~rank~','~typename~','~typeimg~',在227行找到$in_query = "INSERT INTO `#@__arctype`(reid,topid,sortrank,typename,将其替换为:$in_query = "INSERT INTO `#@__arctype`(reid,topid,sortrank,typename,typeimg,在230行找到VALUES('$reid','$topid','$sortrank','$typename',将其替换为:VALUES('$reid','$topid','$sortrank','$typename','$typeimg',保存!2)修改dede/catalog_edit.php文件在41行找到typename='$typename',在其下边新增一行typeimg='$typeimg',3)修改dede/templets/catalog_add.htm模板文件首先在<head>标签种添加<script language='javascript' src="js/main.js"></script>然后随便找个位置,我是在栏目名称下边添加的找到这行代码: <tr> <td class='bline' height="26" style="padding-left:10px;"><font color='red'>栏目名称:</font></td> <td class='bline'><input name="typename" type="text" id="typename" size="30" class="iptxt" /></td> </tr> 在其下边添加如下代码<tr> <td class='bline' height="26" style="padding-left:10px;">栏目缩略图:</td> <td class='bline'> <input name="typeimg" type="text" style="width:300px" id="typeimg" class="alltxt" value="" /> <input type="button" name="set9" value="浏览... "class="coolbg np" style="width:60px" onClick="SelectImage('form1.typeimg','');" /> </td> </tr>保存。4)修改dede/templets/catalog_edit.htm模板文件首先在<head>标签种添加<script language='javascript' src="js/main.js"></script>然后找到栏目名称的位置,<tr> <td class='bline' height="26" style="padding-left:10px;"><font color='red'>栏目名称:</font></td> <td class='bline'><input name="typename" type="text" id="typename" size="30" value="<?php echo $myrow['typename']?>" class="iptxt" /></td> </tr>在它的下边添加如下代码<tr> <td class='bline' height="65" style="padding-left:10px;">栏目缩略图:</td> <td class='bline' > <input name="typeimg" type="text" style="width:300px" id="typeimg" class="alltxt" value="<?php echo $myrow['typeimg']?>" /><input type="button" name="set9" value="浏览... "class="coolbg np" style="width:60px" onClick="SelectImage('form1.typeimg','');" /> </td> </tr>保存即可。 三、如何调用缩略图一般情况下我们调用栏目的时候有2种方式{dede:chanel}和{dede:type},所以我们需要修改下边2个文件
include/taglib/channel.lib.php include/taglib/type.lib.php1)修改include/taglib/channel.lib.php在78 - 94行之间,找到如下代码 if($type=='top') { $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath From `#@__arctype` WHERE reid=0 And ishidden<>1 order by sortrank asc limit 0, $line "; } else if($type=='son') { if($typeid==0) return ''; $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath From `#@__arctype` WHERE reid='$typeid' And ishidden<>1 order by sortrank asc limit 0, $line "; } else if($type=='self') { if($reid==0) return ''; $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath FROM `#@__arctype` WHERE reid='$reid' And ishidden<>1 order by sortrank asc limit 0, $line "; }在每个typename的后边添加typeimg,一共三处,修改后的代码为 if($type=='top') { $sql = "SELECT id,typename,typeimg,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath From `#@__arctype` WHERE reid=0 And ishidden<>1 order by sortrank asc limit 0, $line "; } else if($type=='son') { if($typeid==0) return ''; $sql = "SELECT id,typename,typeimg,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath From `#@__arctype` WHERE reid='$typeid' And ishidden<>1 order by sortrank asc limit 0, $line "; } else if($type=='self') { if($reid==0) return ''; $sql = "SELECT id,typename,typeimg,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath FROM `#@__arctype` WHERE reid='$reid' And ishidden<>1 order by sortrank asc limit 0, $line "; }保存文件。调用时可通过{dede:chanel}标签调用 {dede:channel type='top' row='8'} <li><a href='[field:typelink/]'><img src="[field:typeimg/]" /></a> </li>{/dede:channel} 2)修改include/taglib/type.lib.php 在42行找到$row = $dsql->GetOne("SELECT id,typename, 在其后边添加typeimg,既把它修改成如下: $row = $dsql->GetOne("SELECT id,typename,typeimg, 保存文件。 调用方法,可在任何模板页通过{dede:type}方式调用,如下: {dede:type typeid='5'}<a href="[field:typelink /]"><img src="[field:typeimg /]" /></a>{/dede:type} 3)在当前栏目页调用该栏目的缩略图可以直接使用<img src="{dede:field.typeimg/}" />调用。