<%
'****************************************************
'函数:ArticleContent
'作用:文章内容分页
'用法:ArticleContent(文章完整内容)
'示例:ArticleContent(Rs("Content"))
'注意:文章的编号必须为ID,如show.asp?id=123,否则出错
'示例:www.sohujob.com
'****************************************************
Function ArticleContent(strContent)
'strContent:全部完整的文章内容/最初传入的参数
If InStr(strContent, "[page_break]") <= 0 Then
ArticleContent =strContent
Else
arrContent = Split(strContent, "[page_break]") '取得数组/将文章内容用[page_break]分隔后分别放入数组里
Paginate = UBound(arrContent) + 1 '总页数=数组上限+1
CurrentPage =Request("page")
If CurrentPage = 0 Then
CurrentPage = 1 '当前页=1/意外情况处理
Else
CurrentPage = CLng(CurrentPage) '当前页=1
End If
If CurrentPage < 1 Then CurrentPage = 1 '/意外情况处理
If CurrentPage > Paginate Then CurrentPage = Paginate '当前页=最大页/意外情况处理
If UserArticle = True Then
If CurrentPage = 1 Then
strContent = arrContent(CurrentPage - 1)
strContent = Left(strContent,maxstrlen)
strContent = "<div id=""NewsContentLabel"" class=""NewsContent"">" & strContent & "</div>"
Else
strContent = "<div id=""NewsContentLabel"" class=""NewsContent""></div>"
End If
Else
strContent = "<div id=""NewsContentLabel"" class=""NewsContent"">"& arrContent(CurrentPage - 1)
End If
ArticleContent = ArticleContent & strContent
If UserArticle = True Then
ArticleContent = ArticleContent & "</p></div><div id=""Message"" class=""Message""></div><p align=""center""><b>"
Else
ArticleContent = ArticleContent & "</p></div><p align=""center""><b>"
End If
m_strFileExt = ""
m_strFileUrl = "?id=" & ID & "&Page=" '链接地址:传递文章号与页号
If CurrentPage > 1 Then '当前页大于1时,显示上一页链接
If IsURLRewrite And (CurrentPage-1) = 1 Then
ArticleContent = ArticleContent & "<a href="""& ID & m_strFileExt & """>上一页</a> "
Else
ArticleContent = ArticleContent & "<a href="""& m_strFileUrl & CurrentPage - 1 & m_strFileExt & """>上一页</a> "
End If
End If
For i = 1 To Paginate '生成页号,从1到i,点击可快速转到第i页
If i = CurrentPage Then
ArticleContent = ArticleContent & "<font color=""red"">[" & CStr(i) & "]</font> "
Else
If IsURLRewrite And i = 1 Then
ArticleContent = ArticleContent & "<a href="""& ID & m_strFileExt & """>[" & i & "]</a> "
Else
ArticleContent = ArticleContent & "<a href="""& m_strFileUrl & i & m_strFileExt & """>[" & i & "]</a> "
End if
End If
Next
If CurrentPage < Paginate Then '当前页小于最大页时,显示下一页链接
ArticleContent = ArticleContent & " <a href="""& m_strFileUrl & CurrentPage + 1 & m_strFileExt & """>下一页</a>"
End If
ArticleContent = ArticleContent & "</b></p>"
End If
End Function
%>
在需要分页的地方插入[page_break],(在后台的在线编辑器中0
在显示内容的页面,加入此函数,然后将数据库字段读出,以此格式显示即可:
<%=ArticleContent(Rs("Content"))%>
本例已经过检测,确认正确无误!!!