我写的一个ASP内容分页函数

<%
'****************************************************
'函数: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>&nbsp;&nbsp;"
  Else
   ArticleContent = ArticleContent & "<a href="""& m_strFileUrl & CurrentPage - 1 & m_strFileExt & """>上一页</a>&nbsp;&nbsp;"
  End If
 End If
 For i = 1 To Paginate   '生成页号,从1到i,点击可快速转到第i页
  If i = CurrentPage Then
   ArticleContent = ArticleContent & "<font color=""red"">[" & CStr(i) & "]</font>&nbsp;"
  Else
   If IsURLRewrite And i = 1 Then
    ArticleContent = ArticleContent & "<a href="""& ID & m_strFileExt & """>[" & i & "]</a>&nbsp;"
   Else
    ArticleContent = ArticleContent & "<a href="""& m_strFileUrl & i & m_strFileExt & """>[" & i & "]</a>&nbsp;"
   End if
  End If
 Next
 If CurrentPage < Paginate Then   '当前页小于最大页时,显示下一页链接
  ArticleContent = ArticleContent & "&nbsp;<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"))%>

本例已经过检测,确认正确无误!!!

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值