Follow the normal article system all the way. The background article addition, article retrieval, and article detail page are all operated in the normal way. There is no description here. Please refer to related posts.
It should be noted that [page] needs to delete the spaces in the middle. Because it is repeated with the background paging of Script Home, spaces are added.
Just when adding an article, add a page break where you want it to be paged: [page] (Of course, you can use this symbol casually, such as: [page], &&&, ###, @@@..., as long as It won't appear where the article should be displayed normally.)
I used four pages, the input page (index.asp), the input completion page (add.asp), the article list page (view.asp), and the article content page (text.asp). The first three do not need to be processed. page, looking at the following introduction, I think ordinary birds can do it. The key is the last text.asp, all the codes to implement paging are here.
Step 2: Come
Do some tricks in the dynamic data part of the article body. The following is the code and explanation:
Copy the code as follows:'Here is the code for processing paging
' To be on the safe side, we use the replace function to add a full-width space before and after the paging code
MMText=replace(rs(contents),[ page ], [ page ] )
MMfText= split(MMText,[ page ])
'Use ubound function to get the number of pages to be divided. Note that the subscript value starts from 0
contentNum=ubound(MMfText)
page=Clng(request(page))
if page<1 then
page=1
end if
'In order to look more intuitive, we set the starting page to 1, then add 1 to the total number of pages
if page>contentNum+1 then
page=contentNum+1
end if
'Change to the variable of the side to be displayed obtained from the url parameter above, and display the page in a loop
for i=page to page
response.write MMfText(i-1)
next
' List pagination
if cint(contentNum)>0 then
if page<>1 then
response.write <a href='text.asp?id=&request(id)&&page=&page-1&'>[Previous page]</a>
end if
'Remember that the subscript value is from Starting from 0, we start paging from 1 here, and add 1 to the total
for p=1 to contentNum+1
if page=p then
response.write <a href='text.asp?id=&request(id)&&page=&p&'> <font color=red>[&p&]</font></a>
else
response.write <a href='text.asp?id=&request(id)&&page=&p&'>[&p&]</a>
end if
next
if page<>contentNum+1 then
response.write <a href='text.asp?id=&request(id)&&page=&page+1&'>[next page]</a>
end if
end If
below are articles from other websites, you can also refer to them.
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) and the input completion page (add). .asp), 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 ordinary birds can do it. The key is the last A displasy.asp, all the code to implement paging is here.
Step 2:
Do some tricks in the dynamic data part of the article text. The following is the code and explanation:
Copy the code as follows:
<%
'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 variable the value of the parameter in the page passed, to show other
pagesElse
pageNum=Request(page)
End if
%>
<%
'If you add optional execution UBB code, you can add the following
code'rs(NoUBB) is the field in the database about disabling UBB, 0 means disabling, 1 means executing
If rs(NoUBB)=0 then
'In order to avoid errors when 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 is the key
' We use the split function to take out the article in sections and store them in the variable content
ContentStr=split(Content,|||)
'According to the variable to be displayed just obtained from the URL parameter, display the page in a loop
For i=pageNum to pageNum
%>
<!--This will be the text content 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 the article A paging parameter must be added after the ID parameter: page
%>
<a href=display.asp?ID=<%=rsquest(ID)%>&page=<%=p%> class=><%=p+ 1%></a>
The <% Next %> page
is very simple. If all the comments are deleted, it only has 15 lines of code. However, 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 of errors will not go wrong. Of course, you can increase the number of |||, for example: ||||||, and it will be fine if six | or less appear in the article. , but if there are more than six, there will be page breaks. Just choose a good page break.