kingcms改进之递归多级子栏目一键生成所有文章

[ At 11/20/2008 By wukong   4 comments ]

  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代码,试试吧!呵呵。

下一次,给大家讲讲前台页面如何使用这个函数实现栏目页面调用所有子栏目内容的修改方法。

« kingcms后台列表不显示数据的问题kingcms文章列表状态"不显示"的内容仍然显示的问题解决办法 »
  • 1.Ash
  • 我的逼迫看来是有点小效果的,哈哈。收录后转走哦~哈哈
  • 11/20/2008 6:57:53 AM 回复该留言
  • 2.Ash
  • 修改
    index.asp中
    if len(list)>0 then
    data=kc.GetAllSubListID(list)
    if len(data)>0 then list =list&","&data
    else
    list=list&data
    list=list&","&kc.GetAllsubListID(list)
    end if
    多加了层判断,如果根目录的话就不要","了,好像循环的次数还比以前减少了,测试的结果是
    以前的循环结果会是这样
    lsit_2:1,6,7,8,9,10,11,12,13,14,15,16,17,18,
    6,7,8,9,10,11,12,13,14,15,16,17,18,
    9,10,11,12,13,14,15,16,17,18,
    15,16,17,18
    改成现在的是这样
    lsit_2:1,6,7,8,9,10,11,12,13,14,15,16,17,18
    不知道循环次数少会不会有问题。
    再完善下吧。
  • 11/21/2008 11:10:11 PM 回复该留言
  • 3.认为比你的函数好
  • function king_article_suball(l1) '根据listid递归找到其子listid
    dim ids,tempids,rs
    king_article_suball = l1
    set rs=conn.execute("select listid from kingart_list where listid1 in ("&l1&") ;")
    if not rs.eof and not rs.bof then
    tempids=rs.getString(,,"",",","")
    if len(tempids)>0 and InStr(tempids,",") then
    tempids = left(tempids,len(tempids)-1)
    end if
    rs.close
    king_article_suball=king_article_suball(tempids)&","&king_article_suball
    else
    king_article_suball=l1
    end if
    end function
  • 11/3/2009 12:14:55 PM 回复该留言
  • 4.wukong
  • 什么好不好啊,能用就可以,俺的早不用这函数了,太慢这方法,俺用更快的
  • 11/5/2009 9:54:54 AM 回复该留言

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

Powered By 空空如也 

Copyright 167-2009 www.7es.cn . Some Rights Reserved. Email:iamwgh@msn.com QQ:49556
Friends site:Null