当前位置:首页 > 代码 > 正文

文章分页代码(文章怎么分页)

admin 发布:2022-12-31 22:15 46


本篇文章给大家谈谈文章分页代码,以及文章怎么分页对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

长文章按字数分页asp代码

%

function word_pagination(table,content,wordcount)

dim wordPage,action,ami_wordCount,ami_wordSum,ami_wordMod,ami_pageCount,query, ami, ly, temp

wordPage=request.QueryString("wordPage") '获得wordPage

action = "http://" Request.ServerVariables("HTTP_HOST") Request.ServerVariables("SCRIPT_NAME")

'获得网页地址

query = Split(Request.ServerVariables("QUERY_STRING"), "") '获得参数,并分解参数

For Each ly In query

ami = Split(ly, "=")'对参数进行分析

If StrComp(ami(0), "wordPage",vbTextCompare) 0 Then '若参数排除本函数生成的参数

temp = temp ami(0) "=" ami(1) "" '生成参数列表(ami=1)

End If

next

set rs=server.CreateObject("adodb.recordset")

sql="select * from "table" " 'table 表明

rs.open sql,conn,1,1

ami_content=rs(""content"") 'content 进行分页内容的字段名

ami_wordCount=wordCount '每页字数

ami_wordSum=len(ami_content) '计算总字数

ami_wordMod=ami_wordSum mod ami_wordCount '计算最后一页字数

ami_pageCount=int(ami_wordSum/ami_wordCount)'计算页数,总页数=ami_pagecount+1

if wordPage="all" then '单页显示值

wordPage=0

end if

if isEmpty(wordPage)=true then '分析如wordPage无参数传来,wordpage则为首页

wordPage=1

else

wordPage=int(wordPage) '否则等于参数值,并int

end if

if wordPage=0 then '判断参数的几种类型,并根据参数的类型进行分页

ami_content=ami_content

elseif wordPageami_pageCount+1 and wordPage0 then

ami_content=mid(ami_content,ami_wordCount*(wordPage-1)+1,ami_wordCount)

elseif wordPage=ami_pageCount+1 then

ami_content=mid(ami_content,ami_wordCount*ami_pageCount+1,ami_wordMod)

elseif wordPageami_pageCount+1 and wordPage0 then

ami_content="非法参数,请返回"

end if

response.Write ami_content

response.Write "br"

for i=1 to ami_pageCount+1 '页数展示

response.Write "[a href="action"?"temp"wordPage="i""i"/a]"

next

response.Write "[a href="action"?"temp"wordPage=all单页显示/a]"

rs.close

set rs=nothing

end function

调用函数的代码是 %call word_pagination("amily","content",600)%

phpcms V9 文章分页代码在哪修改

v9的分页函数在phpcms\libs\functions\global.func.php下

可以看注释说明

/* 分页函数** @param $num 信息总数

* @param $curr_page 当前分页

* @param $perpage 每页显示数

* @param $urlrule URL规则

* @param $array 需要传递的数组,用于增加额外的方法

* @return 分页

function pages($num, $curr_page, $perpage = 20, $urlrule = '', $array = array(),$setpages = 10){……}/*** 返回分页路径** @param $urlrule 分页规则

* @param $page 当前页

* @param $array 需要传递的数组,用于增加额外的方法

* @return 完整的URL路径*/function pageurl($urlrule, $page, $array = array()){……}/*** URL路径解析,pages 函数的辅助函数** @param $par 传入需要解析的变量 默认为,page={$page}

* @param $url URL地址

* @return URL*/function url_par($par, $url = '') {……}

中源码可以看出主要是pages起作用,pages函数返回的就是html代码了

模板中的html也只能相应地写在了这个函数内,想改其中的html可不是那么容易的事。要注意位置

在网站后台编辑长篇文章时加入 什么简单代码可实现文章分页显示

在button的事件里写上自己的代码,当然就是直接insert innerhtml自己的分页标志了,我目前用的是|,|,|,|,|,|当然可以自定义其他的。首先提供个类库。

1 ContentPager .cs

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.ComponentModel;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Web.SessionState;

/// summary

/// ContentPager 的摘要说明

/// /summary

public class ContentPager : System.Web.UI.Page

{

private System.Web.UI.WebControls.HyperLink lnknext;

private System.Web.UI.WebControls.HyperLink lnkprev;

private System.Web.UI.WebControls.HyperLink lnkfist;

private System.Web.UI.WebControls.HyperLink lnklast;

private System.Web.UI.WebControls.Label pagenum;

private System.Web.UI.WebControls.Label pagecount;

private System.Web.UI.WebControls.Label displaycontent;

public ContentPager()

{

//

// TODO: 在此处添加构造函数逻辑

//

}

public void datapager(string content,string query)

{

string PagerSplit = System.Configuration.ConfigurationManager.AppSettings["PagerSplit"];//从web.config中获取分页符,当然这里可以自己定义,为了方便还是放到配置文件或者数据库中。

string[] contentArray = StringSplit(content, PagerSplit);//这里是一个方法,摘自网上

int PageCount = contentArray.Length;

this.pagecount.Text = "共bfont color='#FF0000'" + PageCount.ToString() + "/font/b页";

int CurPage;

//确定当前页数

if (System.Web.HttpContext.Current.Request.Params["Page"] != null)

{

CurPage = Convert.ToInt32(System.Web.HttpContext.Current.Request.Params["Page"]);

}

else

{

CurPage = 1;

}

if (CurPage 1) CurPage = 1;

if (Convert.ToInt32(System.Web.HttpContext.Current.Request.Params["Page"]) PageCount)

{

CurPage = PageCount;

}

//显示当前页数

this.pagenum.Text = "第bfont color='#FF0000'" + CurPage.ToString() + "/font/b页";

//下一页

if (CurPage != PageCount)

{

lnknext.NavigateUrl = System.Web.HttpContext.Current.Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1) + query;

}

//上一页

if (CurPage 1)

{

lnkprev.NavigateUrl = System.Web.HttpContext.Current.Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1) + query;

}

//第一页

if (CurPage != 1)

{

lnkfist.NavigateUrl = System.Web.HttpContext.Current.Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(1) + query;

}

//最后一页

if (CurPage != PageCount)

{

lnklast.NavigateUrl = System.Web.HttpContext.Current.Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(PageCount) + query;

}

displaycontent.Text = contentArray[CurPage - 1].ToString();

}

#region System.Web.UI.WebControls.HyperLink DisplayContent

public System.Web.UI.WebControls.Label DisplayContent

{

get

{

return this.DisplayContent;

}

set

{

this.displaycontent = value;

}

}

#endregion

#region System.Web.UI.WebControls.HyperLink Lnkprev

public System.Web.UI.WebControls.HyperLink Lnkprev

{

get

{

return this.lnkprev;

}

set

{

this.lnkprev = value;

}

}

#endregion

#region System.Web.UI.WebControls.HyperLink Lnknext

public System.Web.UI.WebControls.HyperLink Lnknext

{

get

{

return this.lnknext;

}

set

{

this.lnknext = value;

}

}

#endregion

#region System.Web.UI.WebControls.HyperLink Lnkfist

public System.Web.UI.WebControls.HyperLink Lnkfist

{

get

{

return this.lnkfist;

}

set

{

this.lnkfist = value;

}

}

#endregion

#region System.Web.UI.WebControls.HyperLink Lnklast

public System.Web.UI.WebControls.HyperLink Lnklast

{

get

{

return this.lnklast;

}

set

{

this.lnklast = value;

}

}

#endregion

#region System.Web.UI.WebControls.Label Pagenum

public System.Web.UI.WebControls.Label Pagenum

{

get

{

return this.pagenum;

}

set

{

this.pagenum = value;

}

}

#endregion

#region System.Web.UI.WebControls.Label Pagecount

public System.Web.UI.WebControls.Label Pagecount

{

get

{

return this.pagecount;

}

set

{

this.pagecount = value;

}

}

#endregion

#region 将字符串分割成数组

/// summary

/// 将字符串分割成数组

/// /summary

/// param name="strSource"/param

/// param name="strSplit"/param

/// returns/returns

public string[] StringSplit(string strSource, string strSplit)

{

string[] strtmp = new string[1];

int index = strSource.IndexOf(strSplit, 0);

if (index 0)

{

strtmp[0] = strSource;

return strtmp;

}

else

{

strtmp[0] = strSource.Substring(0, index);

return StringSplit(strSource.Substring(index + strSplit.Length), strSplit, strtmp);

}

}

#endregion

#region 采用递归将字符串分割成数组

/// summary

/// 采用递归将字符串分割成数组

/// /summary

/// param name="strSource"/param

/// param name="strSplit"/param

/// param name="attachArray"/param

/// returns/returns

private string[] StringSplit(string strSource, string strSplit, string[] attachArray)

{

string[] strtmp = new string[attachArray.Length + 1];

attachArray.CopyTo(strtmp, 0);

int index = strSource.IndexOf(strSplit, 0);

if (index 0)

{

strtmp[attachArray.Length] = strSource;

return strtmp;

}

else

{

strtmp[attachArray.Length] = strSource.Substring(0, index);

return StringSplit(strSource.Substring(index + strSplit.Length), strSplit, strtmp);

}

}

#endregion

}

2 调用部分:

在aspx中增加lable等元素。

asp:label id="currentpage" runat="server" CssClass="gray"当前页/asp:label

asp:label id="totalpage" runat="server" CssClass="gray"Label/asp:label

asp:hyperlink id="lnkfist" runat="server" CssClass="gray"首页/asp:hyperlink|

asp:hyperlink id="lnkprev" runat="server" CssClass="gray"前页/asp:hyperlink|

asp:hyperlink id="lnknext" runat="server" CssClass="gray"下页/asp:hyperlink|

asp:hyperlink id="lnklast" runat="server" CssClass="gray"尾页/asp:hyperlink

在aspx.cs中增加调用代码。

private ContentPager pager;

protected void Page_Load(object sender, EventArgs e)

{

int id = Convert.ToInt32(Request.QueryString["id"]);//接收参数,例如访问这个页是xxx.aspx?id=1

DataSet ds = new DataSet();

//从数据库读内容部分就略掉了

DataRow drow;

drow = ds.Tables[0].Rows[0];

string cont = drow["content"].ToString();//此部分可以把内容中的HTML代码转换一下,我也省略了

//文章分页,关键部分

pager = new ContentPager();

pager.Lnknext = this.lnknext;

pager.Lnkprev = this.lnkprev;

pager.Lnklast = this.lnklast;

pager.Lnkfist = this.lnkfist;

pager.Pagenum = this.currentpage;

pager.Pagecount = this.totalpage;

pager.DisplayContent = this.content;

string query = "id=" + Request.QueryString["id"].ToString();

pager.datapager(cont, query);

}

关于文章分页代码和文章怎么分页的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/33059.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载