 {"id":225,"date":"2010-09-14T11:57:54","date_gmt":"2010-09-14T03:57:54","guid":{"rendered":"http:\/\/www.qyuef.com\/?p=225"},"modified":"2010-09-14T11:57:54","modified_gmt":"2010-09-14T03:57:54","slug":"%e5%88%86%e4%ba%ab%e4%b8%80%e4%b8%aa%e4%b8%8d%e9%94%99%e7%9a%84php%e5%88%86%e9%a1%b5%e7%b1%bb","status":"publish","type":"post","link":"http:\/\/www.qyuef.com\/?p=225","title":{"rendered":"\u5206\u4eab\u4e00\u4e2a\u4e0d\u9519\u7684php\u5206\u9875\u7c7b"},"content":{"rendered":"<p>&nbsp;&nbsp;&nbsp;&nbsp; \u5728php\u7f51\u7ad9\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4fe1\u606f\u5206\u9875\u4e5f\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u3002\u4f46\u662f\u5bf9\u4e8e\u5f88\u591a\u65b0\u5b66\u4e60php\u7684\u670b\u53cb\u6765\u8bf4\uff0c\u5206\u9875\u662f\u4e00\u4e2a\u5927\u95ee\u9898\uff0c\u5404\u79cd\u83ab\u540d\u5176\u5999\u7684\u95ee\u9898\u90fd\u6709\u3002\u8fd9\u91cc\u5c06\u4e00\u4e2a\u5c01\u88c5\u597d\u7684\u5206\u9875\u7c7b\u5206\u4eab\u51fa\u6765\u3002\u5e0c\u671b\u5927\u5bb6\u6709\u7528\u3002<\/p>\n<pre lang=\"php\" line=\"1\">\n< ?php  \nclass SubPages{  \n    \n  private  $each_disNums;\/\/\u6bcf\u9875\u663e\u793a\u7684\u6761\u76ee\u6570  \n  private  $nums;\/\/\u603b\u6761\u76ee\u6570  \n  private  $current_page;\/\/\u5f53\u524d\u88ab\u9009\u4e2d\u7684\u9875  \n  private  $sub_pages;\/\/\u6bcf\u6b21\u663e\u793a\u7684\u9875\u6570  \n  private  $pageNums;\/\/\u603b\u9875\u6570  \n  private  $page_array = array();\/\/\u7528\u6765\u6784\u9020\u5206\u9875\u7684\u6570\u7ec4  \n  private  $subPage_link;\/\/\u6bcf\u4e2a\u5206\u9875\u7684\u94fe\u63a5  \n  private  $subPage_type;\/\/\u663e\u793a\u5206\u9875\u7684\u7c7b\u578b  \n   \/* \n   __construct\u662fSubPages\u7684\u6784\u9020\u51fd\u6570\uff0c\u7528\u6765\u5728\u521b\u5efa\u7c7b\u7684\u65f6\u5019\u81ea\u52a8\u8fd0\u884c. \n   @$each_disNums   \u6bcf\u9875\u663e\u793a\u7684\u6761\u76ee\u6570 \n   @nums     \u603b\u6761\u76ee\u6570 \n   @current_num     \u5f53\u524d\u88ab\u9009\u4e2d\u7684\u9875 \n   @sub_pages       \u6bcf\u6b21\u663e\u793a\u7684\u9875\u6570 \n   @subPage_link    \u6bcf\u4e2a\u5206\u9875\u7684\u94fe\u63a5 \n   @subPage_type    \u663e\u793a\u5206\u9875\u7684\u7c7b\u578b \n   \n   \u5f53@subPage_type=1\u7684\u65f6\u5019\u4e3a\u666e\u901a\u5206\u9875\u6a21\u5f0f \n         example\uff1a   \u51714523\u6761\u8bb0\u5f55,\u6bcf\u9875\u663e\u793a10\u6761,\u5f53\u524d\u7b2c1\/453\u9875 [\u9996\u9875] [\u4e0a\u9875] [\u4e0b\u9875] [\u5c3e\u9875] \n         \u5f53@subPage_type=2\u7684\u65f6\u5019\u4e3a\u7ecf\u5178\u5206\u9875\u6837\u5f0f \n         example\uff1a   \u5f53\u524d\u7b2c1\/453\u9875 [\u9996\u9875] [\u4e0a\u9875] 1 2 3 4 5 6 7 8 9 10 [\u4e0b\u9875] [\u5c3e\u9875] \n   *\/  \n  function __construct($each_disNums,$nums,$current_page,$sub_pages,$subPage_link,$subPage_type){  \n   $this->each_disNums=intval($each_disNums);  \n   $this->nums=intval($nums);  \n    if(!$current_page){  \n    $this->current_page=1;  \n    }else{  \n    $this->current_page=intval($current_page);  \n    }  \n   $this->sub_pages=intval($sub_pages);  \n   $this->pageNums=ceil($nums\/$each_disNums);  \n   $this->subPage_link=$subPage_link;   \n   $this->show_SubPages($subPage_type);   \n   \/\/echo $this->pageNums.\"--\".$this->sub_pages;  \n  }  \n    \n    \n  \/* \n    __destruct\u6790\u6784\u51fd\u6570\uff0c\u5f53\u7c7b\u4e0d\u5728\u4f7f\u7528\u7684\u65f6\u5019\u8c03\u7528\uff0c\u8be5\u51fd\u6570\u7528\u6765\u91ca\u653e\u8d44\u6e90\u3002 \n   *\/  \n  function __destruct(){  \n    unset($each_disNums);  \n    unset($nums);  \n    unset($current_page);  \n    unset($sub_pages);  \n    unset($pageNums);  \n    unset($page_array);  \n    unset($subPage_link);  \n    unset($subPage_type);  \n   }  \n    \n  \/* \n    show_SubPages\u51fd\u6570\u7528\u5728\u6784\u9020\u51fd\u6570\u91cc\u9762\u3002\u800c\u4e14\u7528\u6765\u5224\u65ad\u663e\u793a\u4ec0\u4e48\u6837\u5b50\u7684\u5206\u9875   \n   *\/  \n  function show_SubPages($subPage_type){  \n    if($subPage_type == 1){  \n    $this->subPageCss1();  \n    }elseif ($subPage_type == 2){  \n    $this->subPageCss2();  \n    }  \n   }  \n    \n    \n  \/* \n    \u7528\u6765\u7ed9\u5efa\u7acb\u5206\u9875\u7684\u6570\u7ec4\u521d\u59cb\u5316\u7684\u51fd\u6570\u3002 \n   *\/  \n  function initArray(){  \n    for($i=0;$i< $this->sub_pages;$i++){  \n    $this->page_array[$i]=$i;  \n    }  \n    return $this->page_array;  \n   }  \n    \n    \n  \/* \n    construct_num_Page\u8be5\u51fd\u6570\u4f7f\u7528\u6765\u6784\u9020\u663e\u793a\u7684\u6761\u76ee \n    \u5373\u4f7f\uff1a[1][2][3][4][5][6][7][8][9][10] \n   *\/  \n  function construct_num_Page(){  \n    if($this->pageNums < $this->sub_pages){  \n    $current_array=array();  \n     for($i=0;$i< $this->pageNums;$i++){   \n     $current_array[$i]=$i+1;  \n     }  \n    }else{  \n    $current_array=$this->initArray();  \n     if($this->current_page < = 3){  \n      for($i=0;$i<count($current_array);$i++){  \n      $current_array[$i]=$i+1;  \n      }  \n     }elseif ($this->current_page < = $this->pageNums && $this->current_page > $this->pageNums - $this->sub_pages + 1 ){  \n      for($i=0;$i<count ($current_array);$i++){  \n      $current_array[$i]=($this->pageNums)-($this->sub_pages)+1+$i;  \n      }  \n     }else{  \n      for($i=0;$i<\/count><count ($current_array);$i++){  \n      $current_array[$i]=$this->current_page-2+$i;  \n      }  \n     }  \n    }  \n     \n    return $current_array;  \n   }  \n    \n  \/* \n   \u6784\u9020\u666e\u901a\u6a21\u5f0f\u7684\u5206\u9875 \n   \u51714523\u6761\u8bb0\u5f55,\u6bcf\u9875\u663e\u793a10\u6761,\u5f53\u524d\u7b2c1\/453\u9875 [\u9996\u9875] [\u4e0a\u9875] [\u4e0b\u9875] [\u5c3e\u9875] \n   *\/  \n  function subPageCss1(){  \n   $subPageCss1Str=\"\";  \n   $subPageCss1Str.=\"\u5171\".$this->nums.\"\u6761\u8bb0\u5f55\uff0c\";  \n   $subPageCss1Str.=\"\u6bcf\u9875\u663e\u793a\".$this->each_disNums.\"\u6761\uff0c\";  \n   $subPageCss1Str.=\"\u5f53\u524d\u7b2c\".$this->current_page.\"\/\".$this->pageNums.\"\u9875 \";  \n    if($this->current_page > 1){  \n    $firstPageUrl=$this->subPage_link.\"1\";  \n    $prewPageUrl=$this->subPage_link.($this->current_page-1);  \n    $subPageCss1Str.=\"[<a href=\\\"$firstPageUrl\\\">\u9996\u9875<\/a>] \";  \n    $subPageCss1Str.=\"[<a href=\\\"$prewPageUrl\\\">\u4e0a\u4e00\u9875<\/a>] \";  \n    }else {  \n    $subPageCss1Str.=\"[\u9996\u9875] \";  \n    $subPageCss1Str.=\"[\u4e0a\u4e00\u9875] \";  \n    }  \n     \n    if($this->current_page < $this->pageNums){  \n    $lastPageUrl=$this->subPage_link.$this->pageNums;  \n    $nextPageUrl=$this->subPage_link.($this->current_page+1);  \n    $subPageCss1Str.=\" [<a href=\\\"$nextPageUrl\\\">\u4e0b\u4e00\u9875<\/a>] \";  \n    $subPageCss1Str.=\"[<a href=\\\"$lastPageUrl\\\">\u5c3e\u9875<\/a>] \";  \n    }else {  \n    $subPageCss1Str.=\"[\u4e0b\u4e00\u9875] \";  \n    $subPageCss1Str.=\"[\u5c3e\u9875] \";  \n    }  \n     \n    echo $subPageCss1Str;  \n     \n   }  \n    \n    \n  \/* \n   \u6784\u9020\u7ecf\u5178\u6a21\u5f0f\u7684\u5206\u9875 \n   \u5f53\u524d\u7b2c1\/453\u9875 [\u9996\u9875] [\u4e0a\u9875] 1 2 3 4 5 6 7 8 9 10 [\u4e0b\u9875] [\u5c3e\u9875] \n   *\/  \n  function subPageCss2(){  \n   $subPageCss2Str=\"\";  \n   $subPageCss2Str.=\"<div class='yellow'>\";  \n   $firstPageUrl=$this->subPage_link.\"1\"; \n   $subPageCss2Str.=\"<a href=\\\"$firstPageUrl\\\">1<\/a> \";\n   $a=$this->construct_num_Page();\n   if($a[3]>4){\n\t$subPageCss2Str.=\"...\"; \n\t}\n    for($i=1;$i<count ($a);$i++){  \n    $s=$a[$i];\n\tif($s<$this->pageNums){\n     if($s == $this->current_page ){  \n     $subPageCss2Str.=\"<span class='current'>\".$s.\"<\/span>\";  \n     }else{  \n     $url=$this->subPage_link.$s;  \n     $subPageCss2Str.=\"<a href=\\\"$url\\\">\".$s.\"<\/a>\";  \n     } \n\t }\n    }  \n\tif($a[3]< $this->pageNums and $a[3]>4 ){\n\t$subPageCss2Str.=\"...\"; \n\t}\n\t\n\t$lastPageUrl=$this->subPage_link.$this->pageNums;  \n\t\n       if($this->current_page > 1){  \n    $prewPageUrl=$this->subPage_link.($this->current_page-1);  \n    if($a[3]>4 ){\n\t$subPageCss2Str.=\"<a href=\\\"$lastPageUrl'\\\">{$this->pageNums}<\/a>\";  \n\t} \n    $subPageCss2Str.=\"<a href=\\\"$prewPageUrl\\\">\u4e0a\u4e00\u9875<\/a> \";  \n    }else {  \n\tif($a[3]>4 ){\n\t$subPageCss2Str.=\"<a href=\\\"$lastPageUrl'\\\">{$this->pageNums}<\/a>\"; \n\t} \n    $subPageCss2Str.=\"<span class='disabled'>\u4e0a\u4e00\u9875<\/span> \";  \n    } \n    if($this->current_page < $this->pageNums){   \n    $nextPageUrl=$this->subPage_link.($this->current_page+1);  \n    $subPageCss2Str.=\" <a href=\\\"$nextPageUrl\\\">\u4e0b\u4e00\u9875<\/a> \";   \n    }else {  \n    $subPageCss2Str.=\"<span class='disabled'>\u4e0b\u4e00\u9875<\/span>\";   \n    }  \n    echo $subPageCss2Str;  \n   }  \n}  \n?> \n<\/count><\/div><\/count><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728php\u7f51\u7ad9\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4fe1\u606f\u5206\u9875\u4e5f\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u3002\u4f46\u662f\u5bf9\u4e8e\u5f88\u591a\u65b0\u5b66\u4e60php\u7684\u670b\u53cb\u6765\u8bf4\uff0c\u5206\u9875\u662f\u4e00\u4e2a\u5927\u95ee\u9898\uff0c\u5404\u79cd\u83ab\u540d\u5176\u5999\u7684\u95ee\u9898\u90fd\u6709\u3002\u8fd9\u91cc\u5c06\u4e00\u4e2a\u5c01\u88c5\u597d\u7684\u5206\u9875\u7c7b\u5206\u4eab\u51fa\u6765\u3002\u5e0c\u671b\u5927\u5bb6\u6709\u7528\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[26,62],"tcat":[],"_links":{"self":[{"href":"http:\/\/www.qyuef.com\/index.php?rest_route=\/wp\/v2\/posts\/225"}],"collection":[{"href":"http:\/\/www.qyuef.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.qyuef.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=225"}],"version-history":[{"count":0,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=\/wp\/v2\/posts\/225\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.qyuef.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=225"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=225"},{"taxonomy":"tcat","embeddable":true,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftcat&post=225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}