首页 > 编程 > ASP > 正文

静态生成中实现相关文章列表

2024-05-04 11:06:00
字体:
来源:转载
供稿:网友

以下是代码片段:
<%
’=================================================
’过程名:ShowCorrelative
’作 用:显示相关文章
’参 数:ArticleNum ----最多显示多少篇文章
’ TitleLen ----标题最多字符数,一个汉字=两个英文字符
’=================================================
sub ShowCorrelative(ArticleNum,TitleLen)
dim rs,sql
dim strKey,arrKey,i
if ArticleNum>0 and ArticleNum<=100 then
sql="select top " & ArticleNum
else
sql="Select Top 5 "
end if
’利用"|"符号进行关键字的分割
strKey=mid(rs("Key"),2,len(rs("Key"))-2)
if instr(strkey,"|")>1 then
arrKey=split(strKey,"|")
strKey="((Key like ’%|" & arrKey(0) & "|%’)"
for i=1 to ubound(arrKey)
strKey=strKey & " or (Key like ’%|" & arrKey(i) & "|%’)"
next
strKey=strKey & ")"
else
strKey="(Key like ’%|" & strKey & "|%’)"
end if

sql= & " ID,Title,Author,date,Hits,L.LayoutFileName From Article A inner join Layout L on L.LayoutID=LayoutID Where Deleted=False and Passed=True and " & strKey & " and ID<>" & ID & " Order by ID desc"
Set rs= conn.execute(sql)
if TitleLen<0 or TitleLen>255 then TitleLen=50
if rs.bof and rs.Eof then
response.write "没有相关文章"
else
do while not rs.eof
response.write "<a href=’" & rs("LayoutFileName") & "?ID=" & rs("ID") & "’ title=’文章标题:" & rs("Title") & vbcrlf & "文章作者:" & rs("Author") & vbcrlf & "更新时间:" & rs("date") & vbcrlf & "点击次数:" & rs("Hits") & "’>" & gotTopic(rs("Title"),TitleLen) & "</a>"
rs.movenext
loop
end if
rs.close
set rs=nothing
end sub
%>


定义此过程后,然后再生成静态页面的文件中替换模板标记
(如:htmlmake.asp)
以下是代码片段:
pencat=replace(pencat,"[Xianghuanlist]",ShowCorrelative(5,20))

这样就会生成具有相关文章列表的静态页了!
其中的红色部分是核心的语句,可以只对其进行移植.

以下是代码片段:
<%
’=================================================
’过程名:ShowCorrelative
’作 用:显示相关文章
’参 数:ArticleNum ----最多显示多少篇文章
’ TitleLen ----标题最多字符数,一个汉字=两个英文字符
’=================================================
sub ShowCorrelative(ArticleNum,TitleLen)
dim rs,sql
dim strKey,arrKey,i
if ArticleNum>0 and ArticleNum<=100 then
sql="select top " & ArticleNum
else
sql="Select Top 5 "
end if
’利用"|"符号进行关键字的分割
strKey=mid(rs("Key"),2,len(rs("Key"))-2)
if instr(strkey,"|")>1 then
arrKey=split(strKey,"|")
strKey="((Key like ’%|" & arrKey(0) & "|%’)"
for i=1 to ubound(arrKey)
strKey=strKey & " or (Key like ’%|" & arrKey(i) & "|%’)"
next
strKey=strKey & ")"
else
strKey="(Key like ’%|" & strKey & "|%’)"
end if

sql= & " ID,Title,Author,date,Hits,L.LayoutFileName From Article A inner join Layout L on L.LayoutID=LayoutID Where Deleted=False and Passed=True and " & strKey & " and ID<>" & ID & " Order by ID desc"
Set rs= conn.execute(sql)
if TitleLen<0 or TitleLen>255 then TitleLen=50
if rs.bof and rs.Eof then
response.write "没有相关文章"
else
do while not rs.eof
response.write "<a href=’" & rs("LayoutFileName") & "?ID=" & rs("ID") & "’ title=’文章标题:" & rs("Title") & vbcrlf & "文章作者:" & rs("Author") & vbcrlf & "更新时间:" & rs("date") & vbcrlf & "点击次数:" & rs("Hits") & "’>" & gotTopic(rs("Title"),TitleLen) & "</a>"
rs.movenext
loop
end if
rs.close
set rs=nothing
end sub
%>


定义此过程后,然后再生成静态页面的文件中替换模板标记
(如:htmlmake.asp)
以下是代码片段:
pencat=replace(pencat,"[Xianghuanlist]",ShowCorrelative(5,20))

这样就会生成具有相关文章列表的静态页了!
其中的红色部分是核心的语句,可以只对其进行移植.

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表