|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
sarahfoxnz Smarty Regular
Joined: 11 Apr 2010 Posts: 76
|
Posted: Fri Sep 25, 2015 6:51 am Post subject: Display page numbers (hide outside range) - between ??? |
|
|
Hello.
I'm currently doing a small PHP smarty website, & i have 'pages' to display 10 items per page. (this is OK.)
Ive got the 'result' HTML showing this so far.. however i'm going to create more & more pages as the website grows..
Pages: First .. 2 .. 3 .. 4 .. 5 .. 6 .. 7 .. 8 .. 9 .. 10 .. 11 .. 12 .. 13 .. 14 .. 15 .. 16 .. Last ..
If i'm currently viewing page 10, i'll want something like :-
Pages: First .. .. 6 .. 7 .. 8 .. 9 .. 10 .. 11 .. 12 .. 13 .. 14 .. Last ..
to show page 10, & 3-4 pages either side - hiding the rest of the pages...
I am wondering if there is a way to do a normal foreach loop & do
IF (number) between 5 and 15 - then show it. otherwise dont show....
is there a function / quick way of doing 'between' ?
i am thinking i'll need to do two foreach loops - to show 'before' the current page, and after the current page. is this necessary ? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
|
Back to top |
|
sarahfoxnz Smarty Regular
Joined: 11 Apr 2010 Posts: 76
|
Posted: Fri Sep 25, 2015 10:20 pm Post subject: |
|
|
[quote="mohrt"]This might be of use.
http://phpinsider.com/php/code/SmartyPaginate/[/quote]
Thanks...
I'll look into that, though i think i've solved my problem before i saw your message.
Its a bit messy, but works.
[code]
{math assign="startpage" equation="page-4" page=$page}
{math assign="endpage" equation="page+4" page=$page}
<div style='text-align:center;'>Pages:
{foreach from=$pages key=k item=v name=bobby}
{if $k<2}
<a href="/date/{$pages.$k.page}">{$pages.$k.name}</a> ..
{elseif $smarty.foreach.bobby.last}
<a href="/date/{$pages.$k.page}">{$pages.$k.name}</a>
{elseif ($k eq $page)}
<strong><a href="/date/{$pages.$k.page}">{$pages.$k.name}</a></strong> ..
{elseif ($k gt $startpage) and ($k lt $endpage)}
<a href="/date/{$pages.$k.page}">{$pages.$k.name}</a> ..
{/if}
{/foreach}
[/code]
$k is the count / number of 'pages' I have. (already calculated in my PHP script) |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|