Page 1 of 1
[Solved]123 ...50 51 52 pagination in cgblog and news
Posted: Tue Sep 11, 2012 5:09 am
by carasmo
This code below prints:
Code: Select all
first page previous page 1 2 3 4 5 next page last page
It works with the ajax instructions on CalGuy's site, along with some custom jquery building on Robert's code.
What I would like is that when there are more than a certain amount of pages it does something like the attached photo. Any possibility for this?
Thanks!
Code: Select all
{if $pagenumber <= 1}
{assign var="page_link" value=$nexturl}
{else}
{assign var="page_link" value=$prevurl}
{/if}
{strip}
{if $pagecount > 1}
<ul id="pagenav">
{capture assign="pagenav"}
{* first page *}
{if $pagenumber > $pagecount}
<li><a onclick="ajax_load('{$firsturl}','#results'); return false;" class="pagenav" href="{$firsturl}">First Page</a></li>
{/if}
{* previous page *}
{if $pagenumber > 1}
<li><a onclick="ajax_load('{$prevurl}','#results'); return false;" class="pagenav" href="{$prevurl}">Previous Page</a></li>
{/if}
{* page numbers *}
{if $pagecount > 1}
{section name="pages" start=1 loop=$pagecount+1}
<li>
<a onclick="ajax_load('{$page_link|regex_replace:"/pagenumber=\d+/":"pagenumber=`$smarty.section.pages.index`"}','#results'); return false;" class="pagenav" href="{$page_link|regex_replace:"/pagenumber=\d+/":"pagenumber=`$smarty.section.pages.index`"}">{$smarty.section.pages.index == $pagenumber}
</a>
</li>
{/section}
{/if}
{* next page *}
{if $pagenumber < $pagecount}
<li><a onclick="ajax_load('{$nexturl}','#results'); return false;" class="pagenav" href="{$nexturl}">Next Page</a></li>
{/if} {/capture}
{* last page *}
{if $pagenumber < $pagecount}
<li><a onclick="ajax_load('{$lasturl}','#results'); return false;" class="pagenav" href="{$lasturl}">Last Page</a></li>
{/if}
</ul>
{/if}
{/strip}
Re: I've gotten far.. help with 123... pagination in news/bl
Posted: Tue Sep 11, 2012 5:54 am
by vilkis
I use this code (it is without ajax):
Code: Select all
{*PUSLAPIAVIMAS*}
{if $pagenumber < $pagecount}
{capture assign=pageurl}
{$nextpage|regex_replace:'/href=\"(.*)\"/':'$1'|replace:'<a ':''|replace:'>></a>':''}
{/capture}
{else}
{capture assign=pageurl}
{$prevpage|regex_replace:'/href=\"(.*)\"/':'$1'|replace:'<a ':''|replace:'><</a>':''}
{/capture}
{/if}
{if $pagenumber eq 1}
{capture assign=prevpagestr}
pagenumber=1
{/capture}
{else}
{capture assign=prevpagestr}
pagenumber={$pagenumber-1}
{/capture}
{/if}
{if $pagenumber eq $pagecount}
{capture assign=nextpagestr}
pagenumber={$pagecount}
{/capture}
{else}
{capture assign=nextpagestr}
pagenumber={$pagenumber+1}
{/capture}
{/if}
<a class="aimg" href="{$pageurl|regex_replace:'/pagenumber=(\d+)/':$prevpagestr}">First</a>
{if $pagecount < 6}
{section name=foo start=0 loop=$pagecount step=1}
{capture assign=pagestr}
pagenumber={$smarty.section.foo.iteration}
{/capture}
<a {if $smarty.section.foo.iteration eq $pagenumber}class="selected"{/if} href="{$pageurl|regex_replace:'/pagenumber=(\d+)/':$pagestr}">{$smarty.section.foo.iteration}</a>
{/section}
{else}
{if $pagenumber < 3}
{capture assign=startpage}1{/capture}
{elseif ($pagecount-$pagenumber) < 2}
{capture assign=startpage}{$pagecount-4}{/capture}
{else}
{capture assign=startpage}{$pagenumber-2}{/capture}
{/if}
{section name=foo start=$startpage loop=20 max=5}
{capture assign=pagestr}
pagenumber={$smarty.section.foo.index}
{/capture}
<a {if $smarty.section.foo.index eq $pagenumber}class="selected"{/if}
href="{$pageurl|regex_replace:'/pagenumber=(\d+)/':$pagestr}">{$smarty.section.foo.index}</a>
{/section}
{/if}
<a class="aimg" href="{$pageurl|regex_replace:'/pagenumber=(\d+)/':$nextpagestr}">Last</a>
vilkis
Re: I've gotten far.. help with 123... pagination in news/bl
Posted: Tue Sep 11, 2012 1:28 pm
by carasmo
Thank you!!! I get a smarty error, I there's something missing.
Re: I've gotten far.. help with 123... pagination in news/bl
Posted: Tue Sep 11, 2012 2:08 pm
by carasmo
Thank you! I figured it out. It ROCKS!!! I will now attempt the ajax thing.
Thank you again!
Re: I've gotten far.. help with 123... pagination in news/bl
Posted: Tue Sep 11, 2012 2:24 pm
by vilkis
I corrected that code. Here is another:
Code: Select all
{*PUSLAPIAVIMAS*}
{if $pagecount>1}
{if $pagenumber < $pagecount}
{capture assign=pageurl}
{$nextpage|regex_replace:'/href=\"(.*)\"/':'$1'|replace:'<a ':''|replace:'>></a>':''}
{/capture}
{else}
{capture assign=pageurl}
{$prevpage|regex_replace:'/href=\"(.*)\"/':'$1'|replace:'<a ':''|replace:'><</a>':''}
{/capture}
{/if}
{capture assign=from_start_to_num}
{$pagenumber-2}
{/capture}
{capture assign=from_num_to_end}
{$pagenumber+2}
{/capture}
<nav class="pagination">
<ul>
{if $from_start_to_num>1}
{if $pagenumber eq 1}
<li><a>1</a></li>
{else}
{capture assign=pagestr}
pagenumber=1
{/capture}
<li><a href="{$pageurl|regex_replace:'/pagenumber=(\d+)/':$pagestr}">1</a></li>
{/if}
{if $pagenumber eq 2}
<li><a>2</a></li>
{else}
{capture assign=pagestr}
pagenumber=2
{/capture}
<li><a href="{$pageurl|regex_replace:'/pagenumber=(\d+)/':$pagestr}">2</a></li>
{/if}
<li>...</li>
{capture assign=pagestr}
pagenumber={$pagenumber-1}
{/capture}
<li><a href="{$pageurl|regex_replace:'/pagenumber=(\d+)/':$pagestr}">{$pagenumber-1}</a></li>
<li><a>{$pagenumber}</a></li>
{else}
{section name=foo start=1 loop=$pagenumber+1 step=1}
{capture assign=pagestr}pagenumber={$smarty.section.foo.index}{/capture}
{capture assign=pageurl1}{$pageurl|regex_replace:'/pagenumber=(\d+)/':$pagestr}{/capture}
{if $smarty.section.foo.index eq $pagenumber}
<li><a>{$smarty.section.foo.index}</a></li>
{else}
<li><a href="{$pageurl1}">{$smarty.section.foo.index}</a></li>
{/if}
{/section}
{/if}
{if $from_num_to_end<$pagecount}
{capture assign=pagestr}
pagenumber={$pagenumber+1}
{/capture}
<li><a href="{$pageurl|regex_replace:'/pagenumber=(\d+)/':$pagestr}">{$pagenumber+1}</a></li>
<li>...</li>
{capture assign=pagestr}
pagenumber={$pagecount-1}
{/capture}
<li><a href="{$pageurl|regex_replace:'/pagenumber=(\d+)/':$pagestr}">{$pagecount-1}</a></li>
{capture assign=pagestr}
pagenumber={$pagecount}
{/capture}
<li><a href="{$pageurl|regex_replace:'/pagenumber=(\d+)/':$pagestr}">{$pagecount}</a></li>
{else}
{section name=foo start=$pagenumber+1 loop=$pagecount+1 step=1}
{capture assign=pagestr}pagenumber={$smarty.section.foo.index}{/capture}
{capture assign=pageurl1}{$pageurl|regex_replace:'/pagenumber=(\d+)/':$pagestr}{/capture}
{if $smarty.section.foo.index eq $pagenumber}
<li><a>{$smarty.section.foo.index}</a></li>
{else}
<li><a href="{$pageurl1}">{$smarty.section.foo.index}</a></li>
{/if}
{/section}
{/if}
</ul>
</nav>
{/if}
{* PAGINATION END *}
Re: I've gotten far.. help with 123... pagination in news/bl
Posted: Tue Sep 11, 2012 4:47 pm
by carasmo
That is AWESOME!
I modified with spans instead of a tags and put a selected class, though really not necessary if I just target spans in the css. Here's the modified, wonderfully working version, without the calguy's ajax, but it does work with another script which requires no modifications to the links.
Code: Select all
{capture assign=pagenavigation}
{*pagination begin*}
{if $pagecount>1}
{if $pagenumber < $pagecount}
{capture assign=pageurl}
{$nextpage|regex_replace:'/href=\"(.*)\"/':'$1'|replace:'<a ':''|replace:'>→</a>':''} {*adjusted for my lang file string*}
{/capture}
{else}
{capture assign=pageurl}
{$prevpage|regex_replace:'/href=\"(.*)\"/':'$1'|replace:'<a ':''|replace:'>←</a>':''} {*adjusted for my lang file string*}
{/capture}
{/if}
{capture assign=from_start_to_num}
{$pagenumber-2}
{/capture}
{capture assign=from_num_to_end}
{$pagenumber+2}
{/capture}
<ul id="pagenav">
{if $from_start_to_num>1}
{if $pagenumber eq 1}
<li><span class="selected">1</span></li>
{else}
{capture assign=pagestr}
pagenumber=1
{/capture}
<li><a href="{$pageurl|regex_replace:'/pagenumber=(\d+)/':$pagestr}">1</a></li>
{/if}
{if $pagenumber eq 2}
<li><span class="selected">2</span></li>
{else}
{capture assign=pagestr}
pagenumber=2
{/capture}
<li><a href="{$pageurl|regex_replace:'/pagenumber=(\d+)/':$pagestr}">2</a></li>
{/if}
<li>...</li>
{capture assign=pagestr}
pagenumber={$pagenumber-1}
{/capture}
<li><a href="{$pageurl|regex_replace:'/pagenumber=(\d+)/':$pagestr}">{$pagenumber-1}</a></li>
<li><span class="selected">{$pagenumber}</span></li>
{else}
{section name=foo start=1 loop=$pagenumber+1 step=1}
{capture assign=pagestr}pagenumber={$smarty.section.foo.index}{/capture}
{capture assign=pageurl1}{$pageurl|regex_replace:'/pagenumber=(\d+)/':$pagestr}{/capture}
{if $smarty.section.foo.index eq $pagenumber}
<li><span class="selected">{$smarty.section.foo.index}</span></li>
{else}
<li><a href="{$pageurl1}">{$smarty.section.foo.index}</a></li>
{/if}
{/section}
{/if}
{if $from_num_to_end<$pagecount}
{capture assign=pagestr}
pagenumber={$pagenumber+1}
{/capture}
<li><a href="{$pageurl|regex_replace:'/pagenumber=(\d+)/':$pagestr}">{$pagenumber+1}</a></li>
<li>...</li>
{capture assign=pagestr}
pagenumber={$pagecount-1}
{/capture}
<li><a href="{$pageurl|regex_replace:'/pagenumber=(\d+)/':$pagestr}">{$pagecount-1}</a></li>
{capture assign=pagestr}
pagenumber={$pagecount}
{/capture}
<li><a href="{$pageurl|regex_replace:'/pagenumber=(\d+)/':$pagestr}">{$pagecount}</a></li>
{else}
{section name=foo start=$pagenumber+1 loop=$pagecount+1 step=1}
{capture assign=pagestr}pagenumber={$smarty.section.foo.index}{/capture}
{capture assign=pageurl1}{$pageurl|regex_replace:'/pagenumber=(\d+)/':$pagestr}{/capture}
{if $smarty.section.foo.index eq $pagenumber}
<li><span class="selected">{$smarty.section.foo.index}</span></li>
{else}
<li><a href="{$pageurl1}">{$smarty.section.foo.index}</a></li>
{/if}
{/section}
{/if}
</ul>
{/if}
{/capture}
{*pagination end*}
Re: I've gotten far.. help with 123... pagination in news/bl
Posted: Tue Sep 11, 2012 4:48 pm
by carasmo
THANK YOU!
Re: I've gotten far.. help with 123... pagination in news/bl
Posted: Tue Sep 11, 2012 4:54 pm
by carasmo
They both work, I didn't download the first modified by you code, since I was far into it by then, but here's the first version which works great, but differently:
Also my lang file is different, so adjust accordingly in the → and ← areas in the top part.
Code: Select all
{capture assign=pagenavigation}{*pagination begin*}
{if $pagecount > 1}
<ul id="pagenav">
{*PUSLAPIAVIMAS*}
{if $pagenumber < $pagecount}
{capture assign=page_link}
{$nextpage|regex_replace:'/href=\"(.*)\"/':'$1'|replace:'<a ':''|replace:'>→</a>':''}
{/capture}
{else}
{capture assign=page_link}
{$prevpage|regex_replace:'/href=\"(.*)\"/':'$1'|replace:'<a ':''|replace:'>←</a>':''}
{/capture}
{/if}
{if $pagenumber eq 1}
{capture assign=prevpagestr}
pagenumber=1
{/capture}
{else}
{capture assign=prevpagestr}
pagenumber={$pagenumber-1}
{/capture}
{/if}
{if $pagenumber eq $pagecount}
{capture assign=nextpagestr}
pagenumber={$pagecount}
{/capture}
{else}
{capture assign=nextpagestr}
pagenumber={$pagenumber+1}
{/capture}
{/if}
{if $pagenumber > 1}
<li><a href="{$prevurl}">Previous Page</a></li>
{/if}
{if $pagecount < 6}
{section name=foo start=0 loop=$pagecount step=1}
{capture assign=pagestr}
pagenumber={$smarty.section.foo.iteration}
{/capture}
<li><a {if $smarty.section.foo.iteration eq $pagenumber}
class="selected pagnav" {else}class="pagenav"{/if} href="{$page_link|regex_replace:'/pagenumber=\d+/':$pagestr}">{$smarty.section.foo.iteration}</a>
{/section}</li>
{else}
{if $pagenumber < 3}
{capture assign=startpage}1{/capture}
{elseif ($pagecount-$pagenumber) < 2}
{capture assign=startpage}{$pagecount-4}{/capture}
{else}
{capture assign=startpage}{$pagenumber-2}{/capture}
{/if}
{*$pagecount*}{*page count*}
{section name=foo start=$startpage loop=20 max=5}
{*$smarty.section.foo.index*}{*page number without link*}
{capture assign=pagestr}
pagenumber={$smarty.section.foo.index}
{/capture}
<li><a {if $smarty.section.foo.index eq $pagenumber}
class="selected pagenav"
{else} class="pagenav" {/if} href="{$page_link|regex_replace:'/pagenumber=\d+/':$pagestr}">{$smarty.section.foo.index}</a></li>
{/section}
{/if}
{if $pagenumber < $pagecount}
<li><a class="pagenav" href="{$nexturl}">Next Page</a></li>
{/if}
</ul>
{/if}
{/capture}
{*pagination end*}
Re: [Solved]123 ...50 51 52 pagination in cgblog and news
Posted: Wed Sep 12, 2012 12:24 am
by carasmo
Here's the final result with some CSS and other tweeks
http://forum.cmsmadesimple.org/viewtopi ... 15#p286115