Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Display page numbers (hide outside range) - between ???

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
sarahfoxnz
Smarty Regular


Joined: 11 Apr 2010
Posts: 76

PostPosted: Fri Sep 25, 2015 6:51 am    Post subject: Display page numbers (hide outside range) - between ??? Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Sep 25, 2015 9:42 am    Post subject: Reply with quote

There's no such function, but it really easy to do it yourself.

See http://www.smarty.net/docs/en/language.function.foreach.tpl#foreach.property.iteration
http://www.smarty.net/docs/en/language.function.foreach.tpl#foreach.property.first
http://www.smarty.net/docs/en/language.function.foreach.tpl#foreach.property.last
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Sep 25, 2015 8:03 pm    Post subject: Reply with quote

This might be of use.

http://phpinsider.com/php/code/SmartyPaginate/
Back to top
View user's profile Send private message Visit poster's website
sarahfoxnz
Smarty Regular


Joined: 11 Apr 2010
Posts: 76

PostPosted: Fri Sep 25, 2015 10:20 pm    Post subject: Reply with quote

[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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP