首页 php教程 PHP源码 分页类尾部页码导航

分页类尾部页码导航

May 25, 2016 pm 05:07 PM

分页类——尾部页码导航  

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

<?php

/**

 * 生成Comment的尾部分页导航

 * @author 李俊

 *

 */

class cmtTail{

    private $currentPage;

    private $totalPage;

      

    /**

     * 生成页码导航--总控函数

     * @param string $currentPage 当前页码

     * @param string $totalPage 总页数

     * @throws Exception 页码小于1将会抛出异常

     * @return string

     */

    function __do($currentPage, $totalPage) {

        $this->currentPage=$currentPage;

        $this->totalPage=$totalPage;

        if($this->totalPage<=10){//总页数小于等于10页

            if($this->currentPage==1){//当前页是第一页

                $str='上一页'.$this->currentTag();

                for ($i = 2; $i <= $this->totalPage; $i++) {

                    $str=$str.$this->commonTag($i);

                }

                $str=$str.$this->next();

            }elseif ($this->currentPage==$this->totalPage){//已跳至最后一页

                $str=$this->up();

                for ($i = 1; $i <= $this->totalPage-1; $i++) {

                    $str=$str.$this->commonTag($i);

                }

                $str=$str.$this->currentTag();

                $str=$str.$this->next();

            }else{

                $str=$this->up();

                for($i=1; $i<$this->currentPage; $i++){

                    $str=$str.$this->commonTag($i);

                }

                $str=$str.$this->currentTag();//生成当前页标签

                for ($i = $this->currentPage+1; $i <= $this->totalPage; $i++) {

                    $str=$str.$this->commonTag($i);

                }

                $str=$str.$this->next();

            }

        }elseif ($this->totalPage>10){//页码大于10

            if($this->currentPage==1){//8+2

                $str='上一页'.$this->currentTag();

                for ($i = 2; $i <= 8; $i++) {

                    $str=$str.$this->commonTag($i);

                }

                $str=$str.'...';//添加省略号

                $str=$str.$this->commonTag($this->totalPage-1);

                $str=$str.$this->commonTag($this->totalPage);

            }elseif($this->currentPage==$this->totalPage) {//当前为最后一页

                $str=$this->up();

                $str=$str.$this->commonTag(1);

                $str=$str.'...';//添加省略号

                for ($i = $this->totalPage-6; $i < $this->totalPage; $i++) {

                    $str=$str.$this->commonTag($i);

                }

                $str=$str.$this->currentTag();

                $str=$str.$this->next();

            }else {

                if ($this->currentPage<6) {

                    $str=$this->up();

                    for ($i = 1; $i < $this->currentPage; $i++) {

                        $str=$str.$this->commonTag($i);

                    }

                    $str=$str.$this->currentTag();

                    for ($i = $this->currentPage+1; $i <= 7; $i++) {

                        $str=$str.$this->commonTag($i);

                    }

                    $str=$str.'...';//添加省略号

                    $str=$str.$this->commonTag($this->totalPage);

                    $str=$str.$this->next();

                }else {

                    if ($this->currentPage>=$this->totalPage-4) {

                        $str=$this->up();

                        $str=$str.$this->commonTag(1);

                        $str=$str.'...';//添加省略号

                        for ($i = $this->totalPage-6; $i < $this->currentPage; $i++) {

                            $str=$str.$this->commonTag($i);

                        }

                        $str=$str.$this->currentTag();

                        for ($i = $this->currentPage+1; $i <= $this->totalPage; $i++) {

                            $str=$str.$this->commonTag($i);

                        }

                        $str=$str.$this->next();

                    }elseif ($this->currentPage<$this->totalPage-4){//1+5+1

                        $str=$this->up();

                        $str=$str.$this->commonTag(1);

                        $str=$str.'...';//添加省略号

                        $str=$str.$this->commonTag($this->currentPage-2);

                        $str=$str.$this->commonTag($this->currentPage-1);

                        $str=$str.$this->currentTag();

                        $str=$str.$this->commonTag($this->currentPage+1);

                        $str=$str.$this->commonTag($this->currentPage+2);

                        $str=$str.'...';//添加省略号

                        $str=$str.$this->commonTag($this->totalPage);

                        $str=$str.$this->next();

                    }

                };

            }

        }elseif ($this->totalPage<=0){

            throw new Exception("页面不可能小于1");

        }

        return $str;

    }

    /**

     * 一般标签

     * @param int $param 页码

     * @return string

     */

    function commonTag($param) {

        return '<a page="'.$param.'">'.$param.'</a>';

    }

    /**

     * 生成当前页标签

     * @param int $param 页码

     * @return string

     */

    function currentTag() {

        return '<strong id="on">'.$this->currentPage.'</strong>';

    }

    /**

     * 生成下一页标签

     * @param int $param 下一页页码

     * @return string

     */

    function next() {

        if ($this->currentPage==$this->totalPage) {

            return '下一页';

        }

        return '<a page="'.($this->currentPage+1).'">下一页</a>';

    }

    /**

     * 生成上一页标签

     * @param int $param 上一页页码

     * @return string

     */

    function up() {

        if ($this->currentPage==1){

            return '上一页';

        }else{

            return '<a page="'.($this->currentPage-1).'">上一页</a>';

        }

    }

    /**

     * 实例化cmtTail,

     * 功能:生成Comment的尾部分页导航

     * @param string $currentPage 当前页码

     * @param string $totalPage 总页数

     * @return string 返回html标签字符串

     */

    static function GO($currentPage, $totalPage) {

        $p=new cmtTail();

        return $p->__do($currentPage, $totalPage);

    }

}

登录后复制

                                   

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前 By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前 By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热门文章标签

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)