我們用織夢(mèng)制作企業(yè)網(wǎng)站時(shí),因?yàn)橛泻芏嗟臋谀浚總€(gè)欄目的圖片都不一樣,單獨(dú)調(diào)用這些圖片比較麻煩,我們可以簡(jiǎn)單的進(jìn)行小的二次開(kāi)發(fā),實(shí)現(xiàn)每個(gè)欄目都有上傳欄目縮略圖的功能,以便我們?cè)谇岸舜a實(shí)現(xiàn)調(diào)用,這樣就變得簡(jiǎn)單很多,也容易修改!(如圖):
上圖是修改后的,每個(gè)欄目可以上傳相應(yīng)的圖片,下面來(lái)開(kāi)始二次開(kāi)發(fā)的教程!
第一步:執(zhí)行SQL命令為數(shù)據(jù)庫(kù)的欄目表結(jié)構(gòu)添加一個(gè)字段(執(zhí)行選多行命令)
alter table `dede_arctype` add `typeimg` char(100) NOT NULL default '';
第二步:修改涉及到文件:
dede/catalog_add.php
dede/catalog_edit.php
dede/templets/catalog_add.htm
dede/templets/catalog_edit.htm
include/taglib/channel.lib.php
1、修改dede/catalog_add.php文件
打開(kāi)查找
$queryTemplate = "INSERT INTO `arctype`
將
(reid,topid,sortrank,typename,typedir,
替換為
(reid,topid,sortrank,typename,typedir,typeimg,
將
('~reid~','~topid~','~rank~','~typename~','~typedir~',
替換為
('~reid~','~topid~','~rank~','~typename~','~typedir~','~typeimg~',
查找
$in_query = "INSERT INTO `arctype`
將
(reid,topid,sortrank,typename,typedir,
替換為
(reid,topid,sortrank,typename,typedir,typeimg,
將
('$reid','$topid','$sortrank','$typename','$typedir',
替換為
('$reid','$topid','$sortrank','$typename','$typedir','$typeimg',
保存此文件!
2、修改dede/catalog_edit.php文件
查找
$upquery = "UPDATE `arctype` SET
在 typedir='$typedir', 其下面增加一行:
typeimg='$typeimg',
保存此文件!
3、修改dede/templets/catalog_add.htm文件
在最上面找到這段代碼
<title>欄目管理</title>
<link href="css/base.css" rel="stylesheet" type="text/css">
替換為:
<title>欄目管理</title>
<link href="css/base.css" rel="stylesheet" type="text/css">
<script language="javascript" src="../include/js/dedeajax2.js"></script>
<script language='javascript' src="js/main.js"></script>
<script type="text/javascript" src="js/calendar/calendar.js"></script>
查找
<tr>
<td height="26" style="padding-left:10px;">列表命名規(guī)則:</td>
<td><input name="namerule2" type="text" id="namerule2" value="{typedir}/list_{tid}_{page}.html" class="pubinputs" style="width:250px" />
<img src="images/help.gif" alt="幫助" width="16" height="16" border="0" style="cursor:pointer" onClick="ShowHide('helpvar3')"/></td>
</tr>
在標(biāo)簽下面增加一行:
<tr>
<td width="90" style="padding-left:10px;">欄目圖片:</td>
<td width="560"><table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td height="30"><input name="typeimg" type="text" id="typeimg" style="width:240px" />
<input type="button" value="本地上傳" style="width:70px;cursor:pointer;display:none" />
<iframe name='uplitpicfra' id='uplitpicfra' src='' style='display:none'></iframe>
<span class="litpic_span">
<input name="litpic" type="file" id="litpic" onChange="SeePicNew(this, 'divpicview', 'uplitpicfra', 165, 'archives_add.php');" size="1" class='np coolbg'/>
</span>
<input type="button" name="Submit2" value="選擇圖片" style="margin-left:8px;" onClick="SelectImage('form1.typeimg','small');" class='np coolbg'/>
<input type="button" name="Submit2" value="裁剪" style="margin-left:8px;" onClick="imageCut('typeimg');" class='np coolbg'/>
<input type='checkbox' class='np' name='ddisremote' value='1' id='ddisremote'/>
遠(yuǎn)程<br />
(欄目模板里用{dede:field.typeimg /}調(diào)用 </td>
</tr>
</table></td>
<td width="150" align="center"><div id='divpicview' class='divpre'></div></td>
</tr>
保存此文件!
4、修改dede/templets/catalog_edit.htm文件
在最上面找到這段代碼
<title>欄目管理</title>
<link href="css/base.css" rel="stylesheet" type="text/css">
替換為:
<title>欄目管理</title>
<link href="css/base.css" rel="stylesheet" type="text/css">
<script language="javascript" src="../include/js/dedeajax2.js"></script>
<script language="javascript" src="js/main.js"></script>
<script type="text/javascript" src="js/calendar/calendar.js"></script>
查找
<tr>
<td height="26" style="padding-left:10px;">列表命名規(guī)則:</td>
<td><input name="namerule2" type="text" id="namerule2" value="<?php echo $myrow['namerule2']?>" size="40" class="iptxt" />
<img src="images/help.gif" alt="幫助" width="16" height="16" border="0" style="cursor:pointer" onClick="ShowHide('helpvar3')"/></td>
</tr>
在其下面增加一行:
<tr>
<td width="90" height="81" style="padding-left:10px;">欄目圖片:</td>
<td width="500"><input name="typeimg" type="text" id="typeimg" style="width:300px" value="<?php echo $myrow['typeimg']?>">
<input type="button" name="Submit" value="瀏覽..." style="width:70px" onClick="SelectImage('form1.typeimg','');">
<input type="button" name="Submit2" value="裁剪" style="margin-left:8px;" onClick="imageCut('typeimg');" class='np coolbg'/>
<input type='checkbox' class='np' name='ddisremote' value='1'>
遠(yuǎn)程<br />
(欄目模板里用{dede:field.typeimg /}調(diào)用) </td>
<td align="center"><img src="<?php if($myrow['typeimg']!="") echo $myrow['typeimg']; else echo "images/pview.gif";?>" width="150" height="100" id="picview" name="picview"></td>
</tr>
保存此文件!
到這里已經(jīng)基本修改完成!
欄目圖片的添加或修改圖片時(shí)在 (欄目管理>高級(jí)選項(xiàng))里面就會(huì)自動(dòng)出現(xiàn)欄目圖片添加的選擇,點(diǎn)擊選擇圖片,彈出窗口內(nèi)選擇瀏覽上傳就OK。
注意:前臺(tái)欄目標(biāo)簽調(diào)用的時(shí)候,還需要改一個(gè)文件,才能實(shí)現(xiàn)欄目圖片顯示,否則只能通過(guò)sql語(yǔ)句才能顯示圖片。
第三步:縮略圖調(diào)用
打開(kāi):include/taglib/channel.lib.php
查找
if($type=='top')
將
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 ";
}
替換為
if($type=='top')
{
$sql = "SELECT id,typename,typedir,typeimg,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,typeimg,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,typeimg,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
FROM `arctype` WHERE reid='$reid' And ishidden<>1 order by sortrank asc limit 0, $line ";
}
導(dǎo)航欄目調(diào)用方法:
<img src=”[field:typeimg/]” />
第四步:文章內(nèi)容頁(yè)調(diào)用
如果想同時(shí)在文章內(nèi)容頁(yè)調(diào)用欄目圖片打開(kāi),修改\include\arc.archives.class.php
查找
if($this->ChannelUnit->ChannelInfos['issystem']!=-1)
將
if($this->ChannelUnit->ChannelInfos['issystem']!=-1)
{
// 如果當(dāng)前文檔不是系統(tǒng)模型,為單表模型
$query = "SELECT arc.*,tp.reid,tp.typedir,ch.addtable
FROM `archives` arc
LEFT JOIN arctype tp on tp.id=arc.typeid
LEFT JOIN channeltype as ch on arc.channel = ch.id
WHERE arc.id='$aid' ";
$this->Fields = $this->dsql->GetOne($query);
替換為
if($this->ChannelUnit->ChannelInfos['issystem']!=-1)
{
// 如果當(dāng)前文檔不是系統(tǒng)模型,為單表模型
$query = "SELECT arc.*,tp.reid,tp.typedir,typeimg,ch.addtable
FROM `archives` arc
LEFT JOIN arctype tp on tp.id=arc.typeid
LEFT JOIN channeltype as ch on arc.channel = ch.id
WHERE arc.id='$aid' ";
$this->Fields = $this->dsql->GetOne($query);
保存此文件!
如果大家還想在{dede:type typeid='欄目id'} {/dede:type} 這個(gè)標(biāo)簽也調(diào)用欄目圖片,道理是一樣的,找到 include/taglib/type.lib.php
查找
$row = $dsql->GetOne("SELECT id,typename,typedir,
替換為
$row = $dsql->GetOne("SELECT id,typename,typedir,typeimg,
即可!
到這里就已經(jīng)完成了。是不是很簡(jiǎn)單也很實(shí)用呢,希望大家越學(xué)越好!