正文直接开始
直接附上代码,asp函数使用简单,如有疑问可评论提出!
<% '**************************************************** '函数:ArticleContent '作用:文章内容分页 '用法:ArticleContent(文章完整内容) '示例:ArticleContent(Rs("Content")) '注意:文章的编号必须为ID,如content.asp?id=123,否则出错 '**************************************************** Function ArticleContent(strContent) dim arrContent, Paginate, CurrentPage, UserArticle, m_strFileExt, m_strFileUrl, IsURLRewrite '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 %>
转载请注明:Rockyxia Web技术博客 » 分享一个asp内容分页函数
感谢阅读,如果您发现文章中有表述不准确,欢迎提出来,也欢迎交流相关问题,你可以去这里进行一对一问答交流。