Hi to all.
I managed to add a pagination feature, at least for the "default" page.
First, we must change the code that retrieves the articles (rsArticles):
<%
Dim rsArticles
Dim TotalPages
Dim CurPage
CurPage = Request.QueryString("p")
if CurPage = "" then CurPage = 1
Dim CountPage
CountPage = 0
Set rsArticles = Server.CreateObject("ADODB.Recordset")
rsArticles.ActiveConnection = MM_blog_STRING
rsArticles.Source = "SELECT BlogID, BlogHeadline, BlogHTML, BlogDate, BlogCat, BlogAuthor, BlogCommentInclude, BlogReadMore, BlogDraft, CatID, CatName, CatDesc, fldAuthorID, fldAuthorRealName, (SELECT COUNT(*) FROM tblComment WHERE tblComment.BlogID = tblBlog.BlogID AND tblComment.CommentInclude = 1) as CommentCount, (SELECT COUNT(*) FROM tblBlog WHERE BlogCat = CatID AND BlogDraft <> 1) as CategoryCount FROM tblBlog, tblCat, tblAuthor WHERE BlogCat = CatID AND tblBlog.BlogAuthor = tblAuthor.fldAuthorID AND tblBlog.BlogDraft <> 1 ORDER BY BlogDate DESC"
rsArticles.CursorType = 2 ' original = 0
rsArticles.CursorLocation = 3 ' original = 2
rsArticles.CacheSize = rsBlogSite.Fields.Item("BlogPosts").Value 'added
rsArticles.LockType = 1
rsArticles.Open()
rsArticles.MoveFirst
rsArticles.PageSize = rsBlogSite.Fields.Item("BlogPosts").Value
TotalPages = rsArticles.PageCount
rsArticles.AbsolutePage = CurPage
%>
Then, we change the way we place them in the browser (i basically changed the "while" and added a counter)
<%
Do While ((CountPage < rsArticles.PageSize) AND (NOT rsArticles.EOF))
%>
<h2 id="post-<%=(rsArticles.Fields.Item("BlogID").Value)%>"><a href="/article/<%=(rsArticles.Fields.Item("BlogID").Value)%>/" title="Permalink for <%=(rsArticles.Fields.Item("BlogHeadline").Value)%>"><%=(rsArticles.Fields.Item("BlogHeadline").Value)%></a><a name="<%=(rsArticles.Fields.Item("BlogID").Value)%>" id="<%=(rsArticles.Fields.Item("BlogID").Value)%>"></a></h2>
<div class="stamp">Posted at <%= DoDateTime((rsArticles.Fields.Item("BlogDate").Value), 3, 1033) %> in <a href="/cat/<%=(rsArticles.Fields.Item("CatID").Value)%>/" title="<%=(rsArticles.Fields.Item("CatDesc").Value)%>"><%=(rsArticles.Fields.Item("CatName").Value)%> (<%=(rsArticles.Fields.Item("CategoryCount").Value)%>)</a></div>
<div class="main">
<% if (rsArticles.Fields.Item("BlogReadMore").Value) = 1 Then %>
<p><%=CropSentence(CI_StripHTML(rsArticles.Fields.Item("BlogHTML").Value), 500, "...")%></p>
<h4 align="center"><a href="/article/<%=(rsArticles.Fields.Item("BlogID").Value)%>/#<%=(rsArticles.Fields.Item("BlogID").Value)%>" title="Read More <%=(rsArticles.Fields.Item("BlogHeadline").Value)%>">Read More "<%=(rsArticles.Fields.Item("BlogHeadline").Value)%>"</a></h4>
<% Else %>
<%=readmore(rsArticles.Fields.Item("BlogHTML").Value,rsArticles.Fields.Item("BlogID").Value)%>
<% End If %>
</div>
<div class="meta">
<p>Written by <a href="/author/<%=(rsArticles.Fields.Item("fldAuthorID").Value)%>/" title="<%=(rsArticles.Fields.Item("fldAuthorRealName").Value)%>'s Profile"><%=(rsArticles.Fields.Item("fldAuthorRealName").Value)%></a> on <%= DoDateTime((rsArticles.Fields.Item("BlogDate").Value), 1, 1033) %> | <a href="/article/<%=(rsArticles.Fields.Item("BlogID").Value)%>/#comments" class="commentsLink">Comments (<%=(rsArticles.Fields.Item("CommentCount").Value)%>)</a></p>
</div>
<%
CountPage = CountPage + 1
lastdate = DoDateTime((rsArticles.Fields.Item("BlogDate").Value), 1, 1033)
rsArticles.MoveNext()
Loop
%>
And finally, we add the pagination links:
<%
if CInt(CurPage) <> CInt(TotalPages) then
'We are not at the end, show a next button
Response.Write("<a href=""?p=" & curpage + 1 & """ style=""margin:0 10px;"">« previous entries</a>")
End If
if CurPage > 1 then
'We are not at the beginning, show the prev button
Response.Write("<a href=""?p=" & curpage - 1 & """ style=""margin:0 10px;"">next entries »</a>")
End If
%>
You can see it working in the (coming soon) version of my blog:
www.elflip.infoI hope you find it useful.
