dedecms栏目添加字段--栏目自定义字段

来源:互联网 发布:简单的编程小游戏 编辑:程序博客网 时间:2024/04/29 19:48

http://www.002t.cn/yingxiaoyuwangluo/693.html

我想大家内容模型应该用的都很熟悉了吧。这几天在帮客户开发游戏门户的时候想要做一个自定的功能,要到栏目里面添加字段。

比如我要添加:栏目图片,和栏目关键字等。随便你吧。好。我们现在开始做

第一我们要进去mysql 数据库里添加字段,自己命名好!比如我下面 添加了一个 栏目搜索关键字字段,当然你字段可以自己新建,

找到表  dede_arctype (这个是栏目模型的数据库表,前面是你安装的表名,新手要注意,不要问我,我找不到这个表)

注意。这里老鸟跳过

然后点击

图片1
图片1

在点击添加字段

 

图片2
图片2

添加字段

 

 

 

图片3

图片3

到这里数据库 字段添加好了。

 

接下来我们开始做后台。大家写找到 后台栏目 管理模版!

要更改的 2个 D:\www\dede\templets 模版:catalog_add.htm、catalog_edit.htm

下面就演示一个 

 

图片4
图片4

然后添加 字段表单,这个一般大家都会的

我添加的代码是:

 
 

   <tr> 
            <td height="65">栏目搜索关键字:</td>
            <td> <textarea name="lanmukeywrod" cols="70" rows="4" id="lanmukeywrod"  class="alltxt" ><?php echo $myrow['lanmukeywrod']?></textarea> 
            </td>
          </tr>

 

这里大家注意了。表单的name 和id  要和添加的 mysql表字段一样,不应的话。还要多写个取值代码。一样的话。默认dedecms会自动取的

然后我们做最后一部,把数据添加进去

大家找到: D:\www\dede\catalog_edit.php

目录可能和大家不一样 也就是后台 里面的 catalog_edit.php,catalog_add.php

catalog_edit.php要改的地方有:

 38行
 

$upquery = "Update `dede_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',
     moresite='$moresite',
     `cross`='$cross',
     `content`='$content',
     `crossid`='$crossid',
     `smalltypes`='$smalltypes'
     $uptopsql
 where id='$id' ";

 

sql语句里面添加我们刚才的 字段进去。也就是下面这个代码

 

$upquery = "Update `dede_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',
     moresite='$moresite',
     `cross`='$cross',
     `content`='$content',
     `crossid`='$crossid',
     `smalltypes`='$smalltypes',
     `lanmukeywrod`='$lanmukeywrod'
     $uptopsql
 where id='$id' ";

 

看到了 这个是添加的:`lanmukeywrod`='$lanmukeywrod'

 

 

这个是更新栏目的。catalog_add.php添加。也是同样的办法

 更改地址有:63行   和196行。也是同样办法。添加字段信息 到sql里去 
 

 更改后的代码:

63行:

 $queryTemplate = "insert into`dede_arctype`(reid,topid,sortrank,typename,typedir,isdefault,defaultname,issend,channeltype,
    tempindex,templist,temparticle,modname,namerule,namerule2,ispart,corank,description,keywords,moresite,siteurl,sitepath,ishidden,`cross`,`crossid`,`content`,`smalltypes`,`lanmukeywrod`)
    Values('~reid~','~topid~','~rank~','~typename~','~typedir~','$isdefault','$defaultname','$issend','$channeltype',
    '$tempindex','$templist','$temparticle','default','$namerule','$namerule2','0','0','','','0','','','0','0','0','','','$lanmukeywrod')";

添加了 lanmukeywrod

 

196行:

 

 $in_query = "insert into`dede_arctype`(reid,topid,sortrank,typename,typedir,isdefault,defaultname,issend,channeltype,
    tempindex,templist,temparticle,modname,namerule,namerule2,
    ispart,corank,description,keywords,moresite,siteurl,sitepath,ishidden,`cross`,`crossid`,`content`,`smalltypes`,`lanmukeywrod`)
    Values('$reid','$topid','$sortrank','$typename','$typedir','$isdefault','$defaultname','$issend','$channeltype',
    '$tempindex','$templist','$temparticle','default','$namerule','$namerule2',
    '$ispart','$corank','$description','$keywords','$moresite','$siteurl','$sitepath','$ishidden','$cross','$crossid','$content','$smalltypes','$lanmukeywrod')";

 

 下面说下 如何调用到前台

 
 

{dede:field.lanmukeywrod/}

 在模版里调用这个就可以了!

好了写完了。教程,如果大家转载请著名来源:   http://www.002t.cn/yingxiaoyuwangluo/693.html         智软工作室(小戴)

0 0
原创粉丝点击