TP comes with a paging function, very convenient to use.
Here's how I use it:
1 /***************** pagination Display start*************************/2 $arr _page=$this->page ($user, 1);3 $show=$arr _page[' Show '];4 $Page=$arr _page[' Page '];5 $article=$user->order (' Now ')->limit ($Page->firstrow. ', '.$Page->listrows)Select ();6 if(!Empty($_post[' Seach_classify '])){7 $seach _classify=$_post[' Seach_classify '];8 $arr _page=$this->page ($user, 1, "classify="$seach _classify‘");9 $show=$arr _page[' Show '];Ten $Page=$arr _page[' Page ']; One $Page->setconfig ("prev", "Top"); A -Dump$Page); - $article=$user->order ("Now")->limit ($Page->first. ', '.$Page-prev)->where ("classify="$seach _classify' ")Select (); the } - //dump ($list); - /***************** pagination Display end************************/
A paging function that combines its own packaging:
Public functionPage$db,$num,$where){ $count=$db->where ($where),Count();// $Page=New\think\page ($count,$num);//instantiate the total number of incoming records in a paging class and the number of records displayed per page $show=$Page->show ();//pagination Display Output return $arr _page=Array( "Show" =$show, "page" =$Page, "Count" =$count, ); }
can be implemented query and conditional query paging, here by conditional query paging, although the data can be poor, but then click on the page link of the query to return to the original unconditional query,
I judge here is $_post[' seach_classify ' is not empty to query, but you can understand, if you click on the Query page link, the page will refresh, $_post[' seach_classify '] return is empty,
Now still can not think of solution, hope Expert answer!
Here's my custom pagination effect creation:
To modify the underlying thinkphp/library/think/page.class.php, modify the following:
1 // 2 private $config = array ( 3 ' header ' = ' <span class= ' rows ' > Total%total_row% articles </span> ',//can be directly modified here, can also be set in your method $PAGE-&G T;setconfig ("header", "article") 4 ' prev ' = ' previous page ',//Here ditto 5 ' next ' = ' next ', 6 ' first ' = ' Return to home page ', 7 Last ' = ' ...%total_page% ', 8 ' theme ' = '%first% %link_page%%header%%end% ',//Customize your paging output here, the contents below 9 );
1 //Replace paging content2 $page _str=Str_replace(3 Array('%header% ', '%now_page% ', '%up_page% ', '%down_page% ', '%first% ', '%link_page% ', '%end% ', '%total_row% ',),// Here is what you need to customize4 Array($this->config[' header '],$this->nowpage,$up _page,$down _page,$the _first,$link _page,$the _end,$this->totalrows,$this->totalpages),5 $this->config[' Theme ']);6 return"{$page _str}";
Here is the effect customization:
1 //Digital Connection2 $link _page= "";3 for($i= 1;$i<=$this->rollpage;$i++){4 if(($this->nowpage-$now _cool_page) <= 0 ){5 $page=$i;6}ElseIf(($this->nowpage +$now _cool_page-1) >=$this-totalpages) {7 $page=$this->totalpages-$this->rollpage +$i;8}Else{9 $page=$this->nowpage-$now _cool_page_ceil+$i;Ten } One if($page> 0 &&$page!=$this-nowpage) { A - if($page<=$this-totalpages) { - $link _page. = ' <a class= ' num ' href= '.$this->url ($page) . ' ><div> '.$page. ' </div></a> '///div Here I add myself, in order to customize the effect with CSS! CSS See below the}Else{ - Break; - } -}Else{ + if($page> 0 &&$this->totalpages! = 1){ - $link _page. = ' <span class= ' current ' ><div id= ' nowpage ' > '.$page. ' </div></span> '; + } A } at}
Css:
Div.fenye{background:;text-align:Center;width:800px;margin:15px-400px 0 0; Right:50%;position:Absolute;Box-shadow:0 0 5px #888;}Div.fenye Div{transition:background 0.5s,box-shadow 1s;text-align:Center;width:40px;Height:25px;float: Left;Color:#FFF}Div.fenye Div:hover{background:#FFF;text-align:Center;float: Left;Color:#000;Box-shadow:0 0px 15px #FFF;}Div#nowpage{Box-shadow:0 0px 15px #FFF;Color:#000;background:#FFF;}span.rows{Color:#666;};
: