kingcms 中,支持多级栏目,但是后台生成操作时,不能方便的将所选栏目的所有子栏目的内容全部生成,实际使用中特别麻烦,需要每个栏目点开然后全选生成。
今天对kingcms写了一段代码,可以简单的处理这个问题,下面代码主要针对kingcms的文章模块,其他模块方法类似,只要修改代码中相应表名和字段名即可实现。
首先在kingcms目录中打开page/artilce/fun.asp文件,搜索 end class 这一行,

看清楚,要找到这一行,可以用文本编辑器的搜索功能很容易找到这行代码。然后将下面的函数代码,复制粘贴到这行代码前面,保存关闭fun.asp文件。函数代码如下
'递归查询所有子栏目id,传入参数为要查找的listid,返回值为该listid下面所有子栏目的listid
function GetAllSubListID(listid) '作者 悟空
dim tmplist,havesublist
dim i,data
dim srs
tmplist = ""
havesublist = ""
'先找出传入listid的子栏目'作者 悟空
set srs = conn.execute("select listid from kingart_list where listid1 in (" & listid & ")")
if srs.recordcount>0 then
data = rs.getrows()
for i=0 to ubound(data,2)
if len(tmplist)>0 then
tmplist = tmplist & "," & data(0,i)
else
tmplist = data(0,i)
end if
next
end if
srs.close
'判断子栏目是否还包含子栏目,包含就递归一次本函数'作者 悟空
if len(tmplist)>0 then
set srs = conn.execute("select listid from kingart_list where exists (select listid from kingart_list where listid1 in (" & tmplist & "))")
if srs.recordcount>0 then
data = rs.getrows()
for i=0 to ubound(data,2)
if len(havesublist)>0 then
havesublist = havesublist & "," & data(0,i)
else
havesublist = data(0,i)
end if
next
tmplist = tmplist + "," + GetAllSubListID(havesublist)
end if
srs.close
end if
GetAllSubListID = tmplist
end function
这个函数主要是通过传入的listid参数,递归所有的子栏目listid,勿论多少级栏目,应该都可以全部获取到的。改好fun.asp添加过子栏目递归函数后,下一步就要找到需要的地方调用了。现在我们需要的是后台生成时可以把子栏目也生成,那么需要修改的就是后台的admin/article/index.asp文件了,用文本编辑器打开该文件。打开文件后搜索字符串 case"createpage" 定位到需要修改的代码附件,这行代码下面一行后面添加如图所示代码进行函数调用。

修改后代码如下
修改完毕,保存关闭index.asp文件。
这样,后台就可以一键全选生成所有包括子栏目的内容了,动手修改一下自己的kingcms代码,试试吧!呵呵。
下一次,给大家讲讲前台页面如何使用这个函数实现栏目页面调用所有子栏目内容的修改方法。