上一篇下一篇

很多网站在新闻显示页底部都有提供上一篇下一篇的链接,这边我们写两个函数用以实现该功能:

'函数名:prevpage
'返回值:上一篇新闻的链接
'参数说明:
'id=当前新闻id值
'url=新闻详细页地址。格式:newsview.asp?id=
'itype=显示样式:
'    1:〖上一篇 下一篇〗;默认类型
'    2:〖上一篇:标题 下一篇:标题〗;
'    3:〖上一篇:标题  
'            下一篇:标题〗
function prevpage(id,url,itype)
    Dim temprs,sqlstr
    Set temprs = Server.CreateObject("ADODB.RecordSet")
    Sqlstr = "Select top 1 * from news1 where id<" & id & " order by id desc"
    temprs.open sqlstr,conn,1,2
    If temprs.bof then
        If itype=1 then
            prevpage = "没有了" & "  "
        Elseif itype=2 then
            prevpage = "上一篇:没有了" & "  "
        Elseif itype=3 then
            prevpage = "上一篇:没有了" & "<br />"
        Else
            prevpage = "没有了" & "  "
        End if
    Else
        If itype=1 then
            prevpage = "<a href=""" & url & temprs("id") & """>上一篇</a>" & "  "
        Elseif itype=2 then
            prevpage = "上一篇:<a href=""" & url & temprs("id") & """>" & temprs("title") & "</a>" & "  "
        Elseif itype=3 then
            prevpage = "上一篇:<a href=""" & url & temprs("id") & """>" & temprs("title") & "</a>"     & "<br />"    
        Else
            prevpage = "<a href=""" & url & temprs("id") & """>上一篇</a>" & "  "
        End if
    End if
    temprs.close
    set temprs = nothing
end function

'函数名:nextpage
'返回值:下一篇新闻的链接
'参数说明:
'id=当前新闻id值
'url=新闻详细页地址。格式:newsview.asp?id=
'itype=显示样式:
'    1:〖上一篇 下一篇〗;默认类型
'    2:〖上一篇:标题 下一篇:标题〗;
'    3:〖上一篇:标题  
'            下一篇:标题〗
function nextpage(id,url,itype)
    Dim temprs,sqlstr
    Set temprs = Server.CreateObject("ADODB.RecordSet")
    Sqlstr = "Select top 1 * from news1 where id>" & id & " order by id asc"
    temprs.open sqlstr,conn,1,2
    If temprs.eof then
        If itype=1 then
            nextpage = "没有了"
        Elseif itype=2 then
            nextpage = "下一篇:没有了"
        Elseif itype=3 then
            nextpage = "下一篇:没有了"
        Else
            nextpage = "没有了"
        End if
    Else
        If itype=1 then
            nextpage = "<a href=""" & url & temprs("id") & """>下一篇</a>"
        Elseif itype=2 then
            nextpage = "下一篇:<a href=""" & url & temprs("id") & """>" & temprs("title") & "</a>"
        Elseif itype=3 then
            nextpage = "下一篇:<a href=""" & url & temprs("id") & """>" & temprs("title") & "</a>"
        Else
            nextpage = "<a href=""" & url & temprs("id") & """>下一篇</a>"
        End if
    End if
    temprs.close
    set temprs = nothing
end function

评论: 1 | 引用: 0 | 查看次数: 5010
发表评论
登录后再发表评论!