dedecms模板网,就要的

dede栏目加自定义字段,dedecms栏目加上缩略图上传功能

作者:-1文章来源:未知 点击数:更新时间:2014-01-10 22:56

 执行SQL命令为数据库的栏目表结构添加一个字段

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

打开dede/catalog_add.php 
查找$queryTemplate = "insert into `dede_arctype`

(reid,topid,sortrank,typename,typedir,
替换为

(reid,topid,sortrank,typename,typedir,typeimg,

('~reid~','~topid~','~rank~','~typename~','~typedir~',
替换为

('~reid~','~topid~','~rank~','~typename~','~typedir~','~typeimg~',

打开dede/catalog_edit.php
查找

$upquery = "Update `dede_arctype` set

在其下面新加一行
`typeimg`='$typeimg',


打开dede/templets/catalog_add.htm 
查找 

  <tr>     <td height="26">列表命名规则:</td>

            <td>

           <input name="namerule2" type="text" id="namerule2" value="{typedir}/list_{tid}_{page}.html"  class="pubinputs"  style="width:250px" />

              <img src="img/help.gif" alt="帮助" width="16" height="16" border="0" style="cursor:pointer" onClick="ShowHide('helpvar3')"/></td>

          </tr>


在其下面增加以下内容

          <tr>
            <td height="65" style="padding-left:10px;">栏目图片:</td>
            <td>
                <input name="typeimg" type="text" style="width:250px" id="typeimg" class="alltxt" value="" />
<input type="button" name="set9" value="浏览... "class="coolbg np" style="width:60px" onClick="SelectImage('form1.typeimg','');" />
                </td>
          </tr>
并在文件的head增加以下内容
<script language='javascript' src="js/main.js"></script>

打开dede/templets/catalog_edit.htm 
在刚前面的位置加入:
    <tr>
            <td height="65" style="padding-left:10px;">栏目图片:</td>
            <td>
                <input name="typeimg" type="text" style="width:250px" 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>
说明:下面这句会调用出已添加的路片路径。
<?php echo $myrow['typeimg']?>  

并在文件的head增加以下内容
<script language='javascript' src="js/main.js"></script>

我试了一下在模版里用:{dede:field.typeimg /} 是调不出数据的,所以我改成了SQL调用。
原来是这样的:
{dede:channel type='top' row='13'}
        <li><a href='[field:typeurl/]' [field:rel/]>[field:typeimg/]</a></li>
      {/dede:channel}
在这里面加上[field:typeimg]  是调不出来的,我个人认为栏目缩略图就是通过循环出来的,而循环不出来则意义不大,所以改成了如下:
      {dede:sql sql="SELECT typename,typedir,typeimg FROM dede_arctype"}
         <li><a href="[field:typedir/]">[field:typeimg/]</a></li>
      {/dede:sql}
这样就顺利的调出来了,当然如果你要调用子ID的话,只要加上相应的条件ID调用就可以了。


添加或修改图片时在 栏目管理》高级选项
如果想同时在文章内容页调用打开\include\arc.archives.class.php
查找
if($this->ChannelUnit->ChannelInfos['issystem']!=-1)

$query = "Select arc.*,tp.reid,tp.typedir,ch.addtable
                from `ant_archives` arc
                         left join ant_arctype tp on tp.id=arc.typeid
                          left join ant_channeltype as ch on arc.channel = ch.id
                          where arc.id='$aid' ";
                $this->Fields = $this->dsql->GetOne($query);
替换为
$query = "Select arc.*,tp.reid,tp.typedir,tp.typeimg,ch.addtable
                from `ant_archives` arc
                         left join ant_arctype tp on tp.id=arc.typeid
                          left join ant_channeltype as ch on arc.channel = ch.id
                          where arc.id='$aid' ";
                $this->Fields = $this->dsql->GetOne($query);