今天,我爱模板网给大家带来的教程:给phpcms V9单网页添加自定义字段和调用自定义字段,并且自定义字段可以使用ckeditor编辑器编辑内容。
为了方便说明,我爱模板网将以下图的例子为例:

如上图,这个表格就是一个自定义字段,要求后台可以编辑,并且不止这一个,还有html表格、js表格、cms表格等等,要求调出来,就是这种效果,这肯定需要用到ckeditor。
第一步、假设有五个类似上面的表格,我们就进入数据库,找到“v9_page”这张表,添加下面五个字段:
第二步、找到 phpcms\modules\content\templates\content_page.tpl.php (这个文件是后台单网页编辑页面调用的模板),查找到下面的代码:
1 | < tr >< th width = "80" > <? php echo L('content');?></ th >< td > |
在它的后面添加下面的代码:
02 | < th width = "80" > <? php echo L('GUI');?> </ th > |
04 | < textarea name = "info[GUI]" id = "GUI" ><? php echo $GUI?></ textarea > |
05 | <? php echo form::editor('GUI','full','','','',1,1)?> |
10 | < th width = "80" >Flash</ th > |
12 | < textarea type = "text" name = "info[flash]" id = "flash" ><? php echo $flash?></ textarea > |
13 | <? php echo form::editor('flash','full','','','',1,1)?> |
17 | < th width = "80" >html</ th > |
19 | < textarea type = "text" name = "info[html]" id = "html" ><? php echo $html?></ textarea > |
20 | <? php echo form::editor('html','full','','','',1,1)?> |
24 | < th width = "80" >div+css</ th > |
26 | < textarea type = "text" name = "info[divcss]" id = "divcss" ><? php echo $divcss?></ textarea > |
27 | <? php echo form::editor('divcss','full','','','',1,1)?> |
31 | < th width = "80" >js+jQuery</ th > |
33 | < textarea type = "text" name = "info[js]" id = "js" ><? php echo $js?></ textarea > |
34 | <? php echo form::editor('js','full','','','',1,1)?> |
38 | < th width = "80" >CMS</ th > |
40 | < textarea type = "text" name = "info[cms]" id = "cms" ><? php echo $cms?></ textarea > |
41 | <? php echo form::editor('cms','full','','','',1,1)?> |
注:“<?php echo form::editor('cms','full','','','',1,1)?>”就是调用ckeditor编辑器。其他的类似。
第三步、进入后台,找到单网页编辑页面,可以看到如下效果:

这一步,进本完成了,里面的table内容是添加上去的。
最后一步、调用:
在对应位置调用相应的代码,如CMS的调用代码就是:{$cms}。OK,大功告成!