1. 分页样式为
  2. 在extend\目录下创建page目录,在page目录下创建Page.php文件,将以下代码放入文件中。
  3.  <?php
    namespace page; use think\Paginator; class Page extends Paginator
    { //首页
    protected function home() {
    if ($this->currentPage() > 1) {
    return "<a href='" . $this->url(1) . "' title='首页'>首页</a>";
    } else {
    return "<p>首页</p>";
    }
    } //上一页
    protected function prev() {
    if ($this->currentPage() > 1) {
    return "<a href='" . $this->url($this->currentPage - 1) . "' title='上一页'>上一页</a>";
    } else {
    return "<p>上一页</p>";
    }
    } //下一页
    protected function next() {
    if ($this->hasMore) {
    return "<a href='" . $this->url($this->currentPage + 1) . "' title='下一页'>下一页</a>";
    } else {
    return"<p>下一页</p>";
    }
    } //尾页
    protected function last() {
    if ($this->hasMore) {
    return "<a href='" . $this->url($this->lastPage) . "' title='尾页'>尾页</a>";
    } else {
    return "<p>尾页</p>";
    }
    } //统计信息
    protected function info(){
    return "<p class='pageRemark'>共<b>" . $this->lastPage .
    "</b>页<b>" . $this->total . "</b>条数据</p>";
    } /**
    * 页码按钮
    * @return string
    */
    protected function getLinks()
    { $block = [
    'first' => null,
    'slider' => null,
    'last' => null
    ]; $side = 3;
    $window = $side * 2; if ($this->lastPage < $window + 6) {
    $block['first'] = $this->getUrlRange(1, $this->lastPage);
    } elseif ($this->currentPage <= $window) {
    $block['first'] = $this->getUrlRange(1, $window + 2);
    $block['last'] = $this->getUrlRange($this->lastPage - 1, $this->lastPage);
    } elseif ($this->currentPage > ($this->lastPage - $window)) {
    $block['first'] = $this->getUrlRange(1, 2);
    $block['last'] = $this->getUrlRange($this->lastPage - ($window + 2), $this->lastPage);
    } else {
    $block['first'] = $this->getUrlRange(1, 2);
    $block['slider'] = $this->getUrlRange($this->currentPage - $side, $this->currentPage + $side);
    $block['last'] = $this->getUrlRange($this->lastPage - 1, $this->lastPage);
    } $html = ''; if (is_array($block['first'])) {
    $html .= $this->getUrlLinks($block['first']);
    } if (is_array($block['slider'])) {
    $html .= $this->getDots();
    $html .= $this->getUrlLinks($block['slider']);
    } if (is_array($block['last'])) {
    $html .= $this->getDots();
    $html .= $this->getUrlLinks($block['last']);
    } return $html;
    } /**
    * 渲染分页html
    * @return mixed
    */
    public function render()
    {
    if ($this->hasPages()) {
    if ($this->simple) {
    return sprintf(
    '%s<div class="pagination">%s %s %s</div>',
    $this->css(),
    $this->prev(),
    $this->getLinks(),
    $this->next()
    );
    } else {
    return sprintf(
    '%s<div class="pagination">%s %s %s %s %s %s</div>',
    $this->css(),
    $this->home(),
    $this->prev(),
    $this->getLinks(),
    $this->next(),
    $this->last(),
    $this->info()
    );
    }
    }
    } /**
    * 生成一个可点击的按钮
    *
    * @param string $url
    * @param int $page
    * @return string
    */
    protected function getAvailablePageWrapper($url, $page)
    {
    return '<a href="' . htmlentities($url) . '" title="第"'. $page .'"页" >' . $page . '</a>';
    } /**
    * 生成一个禁用的按钮
    *
    * @param string $text
    * @return string
    */
    protected function getDisabledTextWrapper($text)
    {
    return '<p class="pageEllipsis">' . $text . '</p>';
    } /**
    * 生成一个激活的按钮
    *
    * @param string $text
    * @return string
    */
    protected function getActivePageWrapper($text)
    {
    return '<a href="" class="cur">' . $text . '</a>';
    } /**
    * 生成省略号按钮
    *
    * @return string
    */
    protected function getDots()
    {
    return $this->getDisabledTextWrapper('...');
    } /**
    * 批量生成页码按钮.
    *
    * @param array $urls
    * @return string
    */
    protected function getUrlLinks(array $urls)
    {
    $html = ''; foreach ($urls as $page => $url) {
    $html .= $this->getPageLinkWrapper($url, $page);
    } return $html;
    } /**
    * 生成普通页码按钮
    *
    * @param string $url
    * @param int $page
    * @return string
    */
    protected function getPageLinkWrapper($url, $page)
    {
    if ($page == $this->currentPage()) {
    return $this->getActivePageWrapper($page);
    } return $this->getAvailablePageWrapper($url, $page);
    } /**
    * 分页样式
    */
    protected function css(){
    return ' <style type="text/css">
    .pagination p{
    margin:0;
    cursor:pointer
    }
    .pagination{
    height:40px;
    padding:20px 0px;
    }
    .pagination a{
    display:block;
    float:left;
    margin-right:10px;
    padding:2px 12px;
    height:24px;
    border:1px #cccccc solid;
    background:#fff;
    text-decoration:none;
    color:#808080;
    font-size:12px;
    line-height:24px;
    }
    .pagination a:hover{
    color:#077ee3;
    background: white;
    border:1px #077ee3 solid;
    }
    .pagination a.cur{
    border:none;
    background:#077ee3;
    color:#fff;
    }
    .pagination p{
    float:left;
    padding:2px 12px;
    font-size:12px;
    height:24px;
    line-height:24px;
    color:#bbb;
    border:1px #ccc solid;
    background:#fcfcfc;
    margin-right:8px; }
    .pagination p.pageRemark{
    border-style:none;
    background:none;
    margin-right:0px;
    padding:4px 0px;
    color:#666;
    }
    .pagination p.pageRemark b{
    color:red;
    }
    .pagination p.pageEllipsis{
    border-style:none;
    background:none;
    padding:4px 0px;
    color:#808080;
    }
    .dates li {font-size: 14px;margin:20px 0}
    .dates li span{float:right}
    </style>';
    }
    }

    修改  application\config.php  中的配置文件即可

 //分页配置
'paginate' => [
'type' => 'page\Page',//分页类
'var_page' => 'page',
'list_rows' => 15,
],

over!over!over!

TP5之自定义分页样式的更多相关文章

  1. GridView自定义分页样式(上一页,下一页,到第几页)

    今天要为网站做一个文章列表,发现GridView的分页样式很难看,于是结合网上的例子,自己做了一个.不是很美观,不过还是很实用的,先看下效果吧,如图(1). 图(1)GridView分页效果 自定义G ...

  2. [ Laravel 5.6 文档 ]laravel数据库操作分页(自定义分页实现和自定义分页样式)

    简介 在其他框架中,分页可能是件非常痛苦的事,Laravel 让这件事变得简单.易于上手.Laravel 的分页器与查询构建器和 Eloquent ORM 集成在一起,并开箱提供方便的.易于使用的.基 ...

  3. 修改DeDe标签Pagelist分页样式,自定义分页样式

    我们在用dede仿站的时候,调用文章列表页的分页时,我们会用到: {dede:pagelist listitem="info,index,end,pre,next,pageno" ...

  4. ThinkPHP5自定义分页样式

    1.在thinkphp/library/think/paginator/driver目录下新建文件Page.php 注意命名空间和继承 <?php namespace think\paginat ...

  5. Thinkphp5 自定义分页样式显示页码和数量

    Thinkphp5 自带的分页比较简单,本文通过修改Bootstrap类自定义显示分页的页码和数量 一.修改完成后如下图显示 二.修改Bootstrap代码: 1.为了不改动Bootstrap.php ...

  6. Laravel自定义分页样式

    <?php namespace App\Http\Controllers; use DB; use App\Http\Controllers\Controller; class UserCont ...

  7. tp5的 LayUI分页样式实现

    1.先配置你的分页参数: //分页配置 'paginate'      => [ 'type'      => 'Layui', 'var_page'  => 'page', 'li ...

  8. laravel自定义分页功能的实现:

    laravel版本:5.5.. 执行命令: php artisan vendor:publish --tag=laravel-pagination 在到 resources/views/vendor/ ...

  9. WPF自定义分页控件,样式自定义,简单易用

    WPF自定义分页控件 做了许久伸手党,终于有机会贡献一波,搜索一下WPF分页控件,还是多,但是不太通用,主要就是样式问题,这个WPF很好解决,还有一个就是分页控件嘛,只关心几个数字的变动就行了,把页码 ...

随机推荐

  1. 消息列队 php 基于redis 实现

    说明 消息列队 基于PHP 实现. 之前 用python 的 flower 实现了 列队. 今天这里我们用的是 PHP 来实现: 在实际的业务环境中 PHP 用的多些: PHP 实现列队 最重要的是用 ...

  2. weexpack 的 Login.vue 及 vue 的 Login.vue

    1.登录页 weexpack  Login.vue <!-- 登录页 --> <template> <div class="wrapper"> ...

  3. zedboard中OLED源码

    #include <stdio.h> #include "platform.h" #include "xil_types.h" #include & ...

  4. 使用JXL对EXCLE的导入导出

    import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.Da ...

  5. String 字符串基本使用

    目录 一.JavaDoc解释 二.基础属性和构造函数 三.基本方法说明 一.JavaDoc解释 String类表示字符串,所有Java程序中的字符串像是"abc"都是此类的实例,字 ...

  6. Micro Frontends

    Micro Frontends - extending the microservice idea to frontend development https://micro-frontends.or ...

  7. add time to file name

    add time to file name echo 123 > $(date +"%Y%m%d_%H%M%S").now; mv /mnt/mongodb_data/dat ...

  8. matlab max函数

    >> a=[1,6,3;7,5,6] a = 1 6 3 7 5 6 >> [q,p]=max(a,[],2) 返回每行最大值,q是结果.p是索引 q = 6 7 p = 2 ...

  9. NSTimer 使用小结

    目录 1. NSRunLoopCommonModes和Timer 2. NSThread和Timer 3. GCD中的Timer 返回目录 1. NSRunLoopCommonModes和Timer ...

  10. 解决virtualbox安装增强工具失败的问题

    virtualbox有个增强工具,安装之后用户体验是非常爽的.但是有些时候在安装增强工具会遇到一些小问题,无非是没有安装gcc,make之类的编译工具或是需要安装kernel*.而我遇到的问题在做了这 ...