对于使用ASPCMS的朋友来说一定遇到过这样的情况,首页调用新闻,第一条新闻为头条,下面的要从第二条开始调用,一般的做法为:先调用一条数据
{aspcms:content sort=XXX order=order num=1}
{/aspcms:content}
然后再做判断从第二条开始调用4条内容
{aspcms:content sort=XXX order=order num=5}
{if:[content:i]>1}
从第二条开始的内容
{end if}
{/aspcms:content}
如果要从第20条开始调用,调用5条,那么只能写num=25,然后判断[content:i]>20,感觉比较麻烦。
我们知道操作access的sql没有limit。此文章以下内容为模拟使用limit调用从指定位置开始调用数据。
最后的使用方法为
{aspcms:content sort=XXX num=5 start=10}
{/aspcms:content}
代表的意义是,从第10条开始获取5条内容。相当于limit 10,5。。。。
本文仅仅作为一个参考资料,提供一个思路而已,如果有什么问题还需自行修改~
打开AspCms_MainClass.asp
找到
Public Function parseLoop(Byval str)
dim sqlstart,rs,s,startID,startstr,startnum,lstart,sortArr,sortStr,sortI,labelRuleField,matches,match,labelStr,loopStr,labelArr,lnum,ltype,lsort,lorder,ltime,whereType,whereSort,orderStr,whereTime,sql,DateArray,matchesfield,loopstrTotal,i,sperStrs,spec,sperStr,aboutkey,title,lstar,contentlen,pagecontent
labelRule = "{aspcms:"&str&"([\s\S]*?)}([\s\S]*?){/aspcms:"&str&"}"
labelRuleField = "\["&str&":([\s\S]+?)\]"
regExpObj.Pattern = labelRule
set matches = regExpObj.Execute(content)
for each match in matches
labelStr = match.SubMatches(0)
'echo str & labelStr
loopStr = match.SubMatches(1)
set labelArr = parseArr(labelStr)
lstart=labelArr("start") : lnum = labelArr("num") : ltype = labelArr("type") : lsort = labelArr("sort") : lorder = labelArr("order") : ltime = labelArr("time") : aboutkey = labelArr("tag") : lstar=labelArr("star")
if isNul(ltype) then ltype="all"
if ltype="all" then
whereType=""
end if
if isNul(lnum) then lnum = 10 else lnum = cint(lnum)
sortStr=""
其中获取标签的代码改为:
lstart=labelArr("start") : lnum = labelArr("num") : ltype = labelArr("type") : lsort = labelArr("sort") : lorder = labelArr("order") : ltime = labelArr("time") : aboutkey = labelArr("tag") : lstar=labelArr("star")
在以下位置添加代码
'从指定数目开始查找解决方法
dim startorder
if isNul(lorder) then
startorder = "time"
elseif lorder="id" then
startorder = " order by ContentID desc"
elseif lorder="visits" then
startorder = " order by Visits desc"
elseif lorder="time" then
startorder = " order by AddTime desc"
elseif lorder="order" then
startorder = " order by IsTop desc,isrecommend desc,ContentOrder,AddTime desc"
elseif lorder="istop" then
startorder = " and IsTop order by ContentOrder,AddTime desc"
elseif lorder="isrecommend" then
startorder = " and isrecommend order by ContentOrder,AddTime desc"
elseif lorder="isimagenews" then
startorder = " and IsImageNews order by ContentOrder,AddTime desc"
elseif lorder="isheadline" then
startorder = " and IsHeadline order by ContentOrder,AddTime desc"
elseif lorder="isfeatured" then
startorder = " and IsFeatured order by ContentOrder,AddTime desc"
end if
if isNul(lstart) then
lstart=""
startstr=""
elseif lstart=0 then
lstart="开始位置不能为0"
startstr=""
else
lstart=" top "&cint(lstart)
sqlstart="select "&lstart&" ContentID from {prefix}Content where sortID="&lsort&startorder
set rs=conn.Exec(sqlstart,"r1")
if not rs.eof then
do while not rs.eof
startID=rs(0)
rs.movenext
loop
end if
startstr=" a.ContentID < "&cint(startID)&" and"
end if
将搜索内容的SQL语句改为
sql="select top "&lnum&" ContentID,a.SortID,a.GroupID,a.Exclusive,Title,Title2,TitleColor,IsOutLink,OutLink,Author,ContentSource,ContentTag,Content,ContentStatus,IsTop,Isrecommend,IsImageNews,IsHeadline,IsFeatured,ContentOrder,IsGenerated,Visits,a.AddTime,a.ImagePath,a.IndexImage,a.DownURL,a.PageFileName,a.PageDesc,SortType,SortURL,SortFolder,SortFileName,SortName,ContentFolder,ContentFileName,b.GroupID,b.Exclusive"&sperStr&" from {prefix}Content as a,{prefix}Sort as b where a.LanguageID="&setting.languageID&" and a.SortID=b.SortID and "&startstr&" ContentStatus=1 and TimeStatus=0 "&whereType&whereSort&whereTime&orderStr
前台调用标签 start=NUM (num为指定位置,是一个数值)
注意申明变量