Long article pages are displayed with page breaks. I want to use ASP to implement this function, but I can find that there is only a way to paginate based on the number of words. But this method has a bug, that is, if there is UBB code in your article content, it is very easy. This causes pagination between [code][/code], or simply decomposes [code] into [co and de], causing errors in article display.
The following steps will make this possible.
Step 1:
Follow the normal article system all the way. Adding articles in the background, retrieving articles, and detail pages of articles are all operated in the usual way. There is no description here. Please refer to related posts. Just when adding an article, add a page break where you want it to be paged: "|||" (Of course, you can use this symbol casually, such as: [page], &&&, ###, @@@... , as long as it does not appear where the article is to be displayed normally)
I used four pages, the input page (index.asp), the input completion page (add.asp), the article list page (view.asp), Article content page (display.asp), the first three are pages that do not need to be processed. Looking at the picture below, I think an ordinary bird can do it. The key is the last display.asp, all the codes for paging are here. .
Step 2:
Do some tricks in the dynamic data part of the article body. The following is the code and explanation:
<%
'Here we need to process the received paging parameters to display the content of which page
'The following two sentences are to let the variable pageNum take the value of the first page if no page parameter is passed: 0
If Request("page")="" Then
pageNum=0
'Otherwise, assign the value to the variable as the parameter in the page passed to display other pages.
Else
pageNum=Request("page")
End if
%>
<%
'If you add optional execution UBB code, you can add the following code
'rs("NoUBB") is a field in the database about disabling UBB, 0 means disabled, 1 means executed
If rs("NoUBB")=0 then
'In order to avoid errors in connecting with the article content, use the Replace function to add a full-width before and after the paging code "|||"
'rs("content") is the text field in the database, add UBB here or disable UBB
Content=Replace((unHTML(rs("content"))),"|||"," ||| ")
Elseif rs("NoUBB")=1 then
Content=Replace((ubb(rs("content"))),"|||"," ||| ")
End if
%>
<%
'Here's the key
'We use the split function to extract the article into sections and store them in the variable content
ContentStr=split(Content,"|||")
'According to the variable that is to be displayed just obtained from the URL parameter, the page will be displayed in a loop
For i=pageNum to pageNum
%>
<!--This will be the text of the article-->
<%=ContentStr %>
<% Next %>
</td>
</tr>
<tr>
<td height="30" class="ClassName">This article is divided into
<%
'In the paging area, use ubound(ContentStr) to get how many pages the article is divided into. Note that it starts from 0, so the total number of pages needs to be added by 1
For p = 0 to ubound(ContentStr)
'The link is still this page, but a paging parameter is added after the article ID parameter: page
%>
<a href="display.asp?ID=<%=rsquest("ID")%>&page=<%=p%>" class=""><%=p+1%></a>
<% Next %> page
It's very simple. If you delete all the comments, it will only be 15 lines of code. But it still needs to be processed so that it can have the functions of highlighting the previous page, next page and current page. It will be perfect.
It has been tested. Unless the page break appears in the article, all types will not go wrong. Of course, you can increase the number of |||, for example: ||||||, and then six "|" or less appear in the article. Everything is fine, but if there are more than six, it will break into pages. Just choose a good page break.