欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

栏目添加 增加 自定义字段

shiping1 的头像
可以参考   http://shipingzhong.cn/node/5265

1)在数据库表 dede_arctype 中增加两个字段
firstcustomtitle 第一自定义标题 secondcustomtitle 第二自定义标题

2)在后台/catalog_add.php 约66行的sql字段中增加 firstcustomtitle  secondcustomtitle  字段
修改后大约如下 注意红色部分:

$queryTemplate = "INSERT INTO `#@__arctype`(reid,topid,sortrank,typename,typedir,isdefault,defaultname,issend,channeltype,
 tempindex,templist,temparticle,modname,namerule,namerule2,ispart,corank,description,keywords,seotitle,
moresite,siteurl,sitepath,ishidden,`cross`,`crossid`,`content`,`smalltypes`,
`customcontent`,`xueli`,`firstcustomtitle`,`secondcustomtitle`)
    VALUES('~reid~','~topid~','~rank~','~typename~','~typedir~','$isdefault','$defaultname','$issend','$channeltype',    '$tempindex','$templist','$temparticle','default','$namerule','$namerule2','0','0','','','~typename~','0','','','0','0','0','','',
'$customcontent','$xueli','
$firstcustomtitle','$secondcustomtitle')";

3)在后台/catalog_add.php 约227行的sql字段中增加 firstcustomtitle  secondcustomtitle  字段
修改后大约如下 注意红色部分:

 $in_query = "INSERT INTO `#@__arctype`(reid,topid,sortrank,typename,typedir,isdefault,defaultname,issend,channeltype,tempindex,
templist,temparticle,modname,namerule,namerule2,
ispart,corank,description,keywords,seotitle,
moresite,siteurl,sitepath,ishidden,`cross`,`crossid`,`content`,`smalltypes`,`customcontent`,`xueli`,
`
firstcustomtitle`,`secondcustomtitle`)
    VALUES('$reid','$topid','$sortrank','$typename','$typedir','$isdefault','$defaultname','$issend','$channeltype',
    '$tempindex','$templist','$temparticle','default','$namerule','$namerule2',
 '$ispart','$corank','$description','$keywords','$seotitle','$moresite','$siteurl','$sitepath',
'$ishidden','$cross','$crossid','$content','$smalltypes','$customcontent','$xueli','$firstcustomtitle','$secondcustomtitle')";

4)在后台/catalog_edit.php 约38行的sql字段中增加 firstcustomtitle  secondcustomtitle  字段
修改后大约如下 注意红色部分:

$upquery = "UPDATE `#@__arctype` SET
     issend='$issend',
     sortrank='$sortrank',
     typename='$typename',
     typedir='$typedir',
     isdefault='$isdefault',
     defaultname='$defaultname',
     issend='$issend',
     ishidden='$ishidden',
     channeltype='$channeltype',
     tempindex='$tempindex',
     templist='$templist',
     temparticle='$temparticle',
     namerule='$namerule',
     namerule2='$namerule2',
     ispart='$ispart',
     corank='$corank',
     description='$description',
     keywords='$keywords',
     seotitle='$seotitle',
     moresite='$moresite',
     `cross`='$cross',
     `content`='$content',
     `crossid`='$crossid',
     `smalltypes`='$smalltypes',   
     `customcontent`='$customcontent',   
     `xueli`='$xueli',    
     `firstcustomtitle`='$firstcustomtitle',   
     `secondcustomtitle`='$secondcustomtitle'           
      $uptopsql    
    WHERE id='$id' ";

5)在后台/templets/catalog_add.htm的在约364后增加  firstcustomtitle  secondcustomtitle  字段
大约如下 注意红色部分:
在下面的代码处后增加 自定义的字段
<tr>
            <td style="padding-left:10px;">栏目交叉: <img src="images/help.gif" alt="帮助" width="16" height="16" border="0" style="cursor:pointer" onClick="ShowHide('helpvarco')" /> <br />仅适用[最终列表栏目]</td>
            <td style="padding:3px 0px 3px 0px">
                <input name="cross" type="radio" id="cross0" value="0" class='np' onClick="CheckCross()" checked='1' />
                不交叉
                <input name="cross" type="radio" id="cross1" value="1" class='np' onClick="CheckCross()" />
                自动获取同名栏目内容
                <input name="cross" type="radio" id="cross2" value="2" class='np' onClick="CheckCross()" />
                手工指定交叉栏目ID(用逗号分开)
                <br />
                <textarea name="crossid" cols="50" rows="3" id="crossid" style="display:none" class="alltxt"></textarea>
            </td>
</tr>
 
<!--自定义字段开始-->
<tr> 
            <td class='bline' height="26" style="padding-left:10px;"><font color='green'>第一自定义标题:</font></td>
            <td class='bline'><input name="firstcustomtitle" type="text" id="firstcustomtitle" size="30" value="" class="iptxt" /></td>
           </tr>           
           <tr> 
            <td class='bline' height="26" style="padding-left:10px;"><font color='green'>第二自定义标题:</font></td>
            <td class='bline'><input name="secondcustomtitle" type="text" id="secondcustomtitle" size="30" value="" class="iptxt" /></td>
           </tr> 
<!--自定义字段结束-->

6)在后台/templets/catalog_edit.htm的在约292后增加  firstcustomtitle  secondcustomtitle  字段
大约如下 注意红色部分:
在下面的代码处后增加 自定义的字段

<tr> 
            <td style="padding-left:10px;">栏目交叉:<img src="images/help.gif" alt="帮助" width="16" height="16" border="0" style="cursor:pointer" onClick="ShowHide('helpvarco')" /><br />仅适用[最终列表栏目]</td>
            <td class='bline' style="padding:3px 0px 3px 0px">
                <input name="cross" type="radio" id="cross0" onClick="CheckCross()" value="0" class='np'<?php if($myrow['cross']==0) echo " checked='1' ";?> />
                不交叉
                <input name="cross" type="radio" id="cross1" onClick="CheckCross()" value="1" class='np'<?php if($myrow['cross']==1) echo " checked='1' ";?>/>
                自动获取同名栏目内容
                <input name="cross" type="radio" id="cross2" onClick="CheckCross()" value="2" class='np'<?php if($myrow['cross']==2) echo " checked='1' ";?>/>
                手工指定交叉栏目ID(用逗号分开)
                <br />
                <textarea name="crossid" cols="50" rows="3" id="crossid" style="<?php if($myrow['cross']!=2) echo "display:none";?>" class="alltxt" ><?php echo $myrow['crossid']; ?></textarea>
            </td>
</tr>
 

<!--自定义字段开始-->
 <tr> 
            <td class='bline' height="26" style="padding-left:10px;"><font color='green'>第一自定义标题:</font></td>
            <td class='bline'><input name="firstcustomtitle" type="text" id="firstcustomtitle" size="30" value="<?php echo $myrow['firstcustomtitle']?>" class="iptxt" /></td>
           </tr>  
           <tr> 
            <td class='bline' height="26" style="padding-left:10px;"><font color='green'>第二自定义标题:</font></td>
            <td class='bline'><input name="secondcustomtitle" type="text" id="secondcustomtitle" size="30" value="<?php echo $myrow['secondcustomtitle']?>" class="iptxt" /></td>
           </tr>  
<!--自定义字段结束-->


7)在前台就可以用 [field:firstcustomtitle /] {dede:field.firstcustomtitle /} 
[field:secondcustomtitle /] {dede:secondcustomtitle /}  来获取数据了
 

 
8) include/taglib/channel.lib.php 约 78行左右 以下改为
 if($type=='top')
    {
        $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,
      customcontent, xueli,firstcustomtitle,secondcustomtitle 
          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,
      customcontent, xueli,firstcustomtitle,secondcustomtitle 
          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,
      customcontent, xueli,firstcustomtitle,secondcustomtitle 
            FROM `#@__arctype` WHERE reid='$reid' And ishidden<>1 order by sortrank asc limit 0, $line ";
    }
9) include/taglib/channel.lib.php 约 115行左右 以下改为
if($type=='son' && $reid!=0 && $totalRow==0)
    {
        $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,
      customcontent, xueli,firstcustomtitle,secondcustomtitle 
            FROM `#@__arctype` WHERE reid='$reid' And ishidden<>1 order by sortrank asc limit 0, $line ";
        $dsql->SetQuery($sql);
      $dsql->Execute();
    }

10) /include/taglib/type.lib.php  约 43行左右 以下改为
     $row = $dsql->GetOne("SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,
      customcontent, xueli,firstcustomtitle,secondcustomtitle,content   FROM `#@__arctype` WHERE id='$typeid' ");
普通分类: