Truncate number of pages in pagination

前端 未结 4 977
没有蜡笔的小新
没有蜡笔的小新 2021-01-16 18:44

This might be a quite silly question, but I can\'t figure anything out that might help me go further. I\'m looking to shorten the number of NUMBERS in my page navigation.

4条回答
  •  轮回少年
    2021-01-16 19:31

    This one shows two links before and two after the current requested link:

    5? 5 : $last; } if ($curr1>=$last) { $curr0 = $last-4 < 1 ? 1 : $last-4; $curr1 = $last; } // now print all links: echo '« '; for ($i=$curr0; $i<=$curr1; $i++) { $style = ($i==$current)? 'font-weight:bold':''; echo ' '.$i.' '; } echo '» '; ?>

    This shows links like this: « 13 14 15 16 17 »
    Imho it's not so difficult to add also first five and last five links by adding appropriate conditions.

    Testing script here

提交回复
热议问题