自动识别并执行分页.自动分页部分现在设定为每5000个字符就分页;手动分页部分设定分页符为"|||".
主要思路是:在内容里搜索分页符,如果含有分页符就执行手动分页程序;如果没有分页符就执行自动分页.这样子设置是因为有时候比较懒,懒得都手动分页;而有时候自动分页可能会在效果页面中间拆分,那就糗了...所以做了这么一个页面.不过说好多CMS都有这个功能的...
怎么说都是自己做的,分享出来给大家,共同进步.如果有建议有问题请给我邮件:chire_8@163.com,谢谢大家的支持,你们的支持是我的动力~
<
%
ID
=
Trim
(Request.QueryString(
"
ID
"
))
Sql
=
"
Select * From news_main Where ID=
"
&
ID
Set
Rsl
=
Conn.Execute(Sql)
Content
=
rsl(
"
text1
"
)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
'
判断时候含分页符,下面是自动分页程序
if
instr
(Content,
"
|||
"
)
=
0
then
set
dic
=
fAtPgnt(rsl(
"
text1
"
),
5000
,request.queryString(
"
apid
"
))
response.write dic(
"
cnt
"
)
&
"
<br/>
"
response.write dic(
"
pgnt
"
)
&
"
<br/>
"
set
dic
=
nothing
else
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
'
这里要处理接收到的分页参数,以此来进行显示第几页的内容
'
下面这两句就是如果没有page这个参数传来就让变量pageNum取显示第一页的
值
If
Request(
"
page
"
)
=
""
Then
pageNum
=
0
'
否则就给变量赋值为传递来的page里的参数,来显示其他页
else
pageNum
=
Request(
"
page
"
)
end
if
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
'
如果加了可选执行UBB代码,可以加上下面的代码
'
rs("NoUBB")是数据库里关于禁用UBB的字段,0为禁用,1为执行
If
rs(
"
NoUBB
"
)
=
0
then
'
为避免和文章内容相连出现错误,用Replace函数把分页代码“|||”的前后各
加一个全角的
'
rs("content")是数据库里正文的字段,在这里加上UBB或者禁用UBB
Content
=
Replace
((unHTML(rsl(
"
text1
"
))),
"
|||
"
,
"
|||
"
)
Elseif
rs(
"
NoUBB
"
)
=
1
then
Content
=
Replace
((ubb(rsl(
"
text1
"
))),
"
|||
"
,
"
|||
"
)
End
if
'
这里就是关键了
'
我们用split函数将文章分段取出存入变量content
ContentStr
=
split
(Content,
"
|||
"
)
'
按照刚才从URL参数中取得的要显示那面的那个变量,就循环显示一页
For
i
=
pageNum
to
pageNum
%
>
<
!
--
这里将是文章正文内容
-->
<
%
=
ContentStr(i) %
>
<
%
Next
'
分页的地方,用ubound(ContentStr)取得文章一共分为几页,注意这里是从0
开始,所以总页数需要加1
For
p
=
0
to
ubound
(ContentStr)
'
链接还是本页面,只不过文章ID参数后面还要加上一个分页的参数:page
%
>
[
<
a href
=
"
look.asp?ID=<%=request(
"
ID
"
)%>&page=<%=p%>
"
><
%
=
p
+
1
%
></
a
>
]
<
%
Next
%
>
<
%
End
If
%
>
<
%
Rsq.Close
Set
Rsq
=
Nothing
Rsl.Close
Set
Rsl
=
Nothing
%
>
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
<
%
function
fAtPgnt(aStr,pSize,rId)
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''
'
ASP 通用文章分页函数(非记录集分页), 返回多个结果, 字典实现 By
shawl.qiu
'
http://blog.csdn.net/btbtd
'
2006-09-04
'
''''''''''''''''''''''''''
'
输入参数说明:
'
aStr 为要分页的字符串
'
pSize 为每页大小数字
'
rId 为 URL 参数 ID, 默认为 apid, 由函数里的 rName 变量定义
if
isNumeric
(pSize)
=
false
or
len
(aStr)
=
0
then
exit
function
if
isNull
(rId)
or
rId
=
""
or
isNumeric
(rId)
=
false
then
rId
=
1
'
如
果分页查询ID为空则 ID为
1
dim
aStrLen
'
取文章总长度的变量
aStrLen
=
len
(aStr)
'
智能URL字符串替换
dim
rqs, url, rName
rqs
=
request.ServerVariables(
"
QUERY_STRING
"
)
rName
=
"
apid
"
if
rqs
=
""
then
url
=
"
?
"
&
rName
&
"
=
"
elseif
instr
(rqs,rName)
<>
0
then
url
=
"
?
"
&
replace
(rqs,rName
&
"
=
"
&
rId,
""
)
&
rName
&
"
=
"
else
url
=
"
?
"
&
replace
(rqs,
"
&
"
&
rName
&
"
=
"
&
rId,
""
)
&
"
&
"
&
rName
&
"
=
"
end
if
dim
tPg
'
定义总页数变量
tPg
=
int
(aStrLen
/-
pSize)
*-
1
if
rId
<
1
then
rId
=
1
'
如果分页查询ID小于1, 则为1
if
cLng
(rId)
>
cLng
(tPg)
then
rId
=
tPg
'
如果分页查询ID大于总页数,
则为总页数
dim
cPg
'
定义取当前页字符起始位置变量
if
rId
=
1
then
cPg
=
1
else
cPg
=
pSize
*
(rId
-
1
)
+
1
'
读取文章的起始位
置
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
dim
dic
'
字义字典变量
set
dic
=
createObject
(
"
scripting.dictionary
"
)
if
aStrLen
<=
pSize
then
'
如果分页大小大于正文大小时, 执行以
下操作
dic.add
"
pgnt
"
,
""
'
增加页面连接到字典
'
增加统计信息到字典
dic.add
"
info
"
,
formatNumber
(pSize,
0
)
&
"
字/页
"
&rid&
"
/
"
&tPg&
"
页 共
"
&_
formatNumber
(aStrLen,
0
)
&
"
字
"
dic.add
"
cnt
"
,
mid
(aStr,
1
)
'
增加内容到字典
set
fAtPgnt
=
dic
set
dic
=
nothing
exit
function
end
if
dim
i, temp, temp1
for
i
=
1
to
tPg
'
如果当前查询ID=i, 则加入高亮CSS类
if
strComp
(rId,i,
1
)
=
0
then
temp1
=
"
class=""hl""
"
temp
=
temp
&
"
<a href=""
"
&
url
&
i
&
"
""
"
&
temp1
&
"
>[
"
&
i
&
"
]</a>
"
next
dic.add
"
pgnt
"
, temp
'
增加页面连接到字典
'
增加统计信息到字典
dic.add
"
info
"
,
formatNumber
(pSize,
0
)
&
"
字/页
"
&rid&
"
/
"
&tPg&
"
页 共
"
&_
formatNumber
(aStrLen,
0
)
&
"
字
"
dic.add
"
cnt
"
,
mid
(aStr,cPg,pSize)
'
增加文章内容到字典
set
fAtPgnt
=
dic
set
dic
=
nothing
end function
%
>