paging like stackoverflow's

前端 未结 3 1848
一整个雨季
一整个雨季 2021-02-11 05:24

i\'m a newbie in php especially on making pagination.

my question is, how to make paging like stackoverflow\'s pagination?
i mean paging like this :

1

3条回答
  •  时光说笑
    2021-02-11 05:55

    Somewhat like this(pseudo-code):

    pg = CurrentPageNo
    low = 1
    high = MAX_PAGES
    if (pg-low <=5)
        output 1 to pg-1 [with links]
    else
        output 1..3 [with links]
        output "..."
        output (pg-3) to (pg-1) [with links]
    
    output pg
    
    if (high - pg <=5)
        output pg+1 to high  [with links]
    else
        output (pg+1) to high-3 [with links]
        output "..."
        output (high-2) to high [with links]
    

提交回复
热议问题