Paging - Show multiple page numbers

We’ve been using paging for quite some time now on our website and overall it works great. I’ve now received a request from my users to see if we can add the page numbers instead of just a < prev next > button. It would look similar to this:

< prev 1 2 3 4 5 next >

Has anyone implementing paging with that type of format?

Shane

At one point we had a modified version of the pager macro to do something like what google does:

First … 3 4 5 6 7 8 9 … Last

I think what you want from what i have pasted is just the for each block…

Fair warning: this was for 6.7 and we don’t use the pagination (so this is old and may not work)


#macro(vt_pager $count $thispage $previous_markup $pagetext $next_markup)##
#set($pagination_nav_max = 7)##
#set($pagination_nav_mid = $tools.math.round($tools.math.div($pagination_nav_max,2)))##
#set($pagination_nav_radius = $pagination_nav_mid - 1)##
#set($shift = 0)##
#set($pagination_nav_end = $count)##
#set($showFirst = "false")##
#set($showLast = "false")##
#set($previous = $thispage - 1)##
#set($next = $thispage + 1)##
##
#if($count > $pagination_nav_max)##
##
#if($thispage <= $pagination_nav_mid)
#set($showLast = "true")##
#set($shift = 0)##
#elseif ($thispage >= ($count - $pagination_nav_radius))##
#set($shift = $count - $pagination_nav_max)##
#set($showFirst = "true")##
#else##
#set($shift = $thispage - $pagination_nav_mid)##
#set($showFirst = "true")##
#set($showLast = "true")##
#end## end if thispage <= pagination_nav_mid
##
#set($pagination_nav_end = $pagination_nav_max + $shift)##
#end## end if count > pagination_nav_max
##
#set($pagination_nav_start = 1 + $shift)##
#set($template = $sys.assemblyItem.Template.Name)##
##
#if($count > 1)##
<div id="vt_pagination_info">
#if($showFirst=="true")##
<span id="vt_pagination_first"><a title="Page 1" href="$rx.location.generateToPage($sys.assemblyItem,$template,1)">First</a></span> ##
#end##
#if($previous > 0)## 
<span id="vt_pagination_previous"><a title ="Page ${previous}" href="$rx.location.generateToPage($sys.assemblyItem,$template,$previous)">$previous_markup</a></span> ##
#end##
#foreach($this_page_nav in [$pagination_nav_start..$pagination_nav_end])##
#if($this_page_nav == $thispage)##
<span id="vt_pagination_currentpage">$thispage</span> ##
#else##
<a title="Page ${this_page_nav}" class="vt_pagination_page" href="$rx.location.generateToPage($sys.assemblyItem,$template,$this_page_nav)">$this_page_nav</a> ##
#end## end if this_page_nav == thispage
#end## end foreach this_page_nav in...
#if($next <= $count)##
<span id="vt_pagination_next"><a title="Page ${next}" href="$rx.location.generateToPage($sys.assemblyItem,$template,$next)">$next_markup</a></span> ##
#end##
#if($showLast=="true")##
<span id="vt_pagination_last"><a title="Page ${count}" href="$rx.location.generateToPage($sys.assemblyItem,$template,$count)">Last</a></span> ##
#end##
</div>
#end## end if
##
#end## end macro #vt_pager

Thanks Jitendra, I really appreciate your help on this. I ended up using the whole thing so I could visualize it and walk myself through the code and you are correct on your warning, it mostly worked but I had to do some quick tweaks to get it to work completely.

Here’s the completed code.


##Start vt_pager macro
#macro(vt_pager $count $thispage $firstpage_markup $previous_markup $pagetext $next_markup $lastpage_markup)##
    #set($pagination_nav_max = 7)##
    #set($pagination_nav_mid = $tools.math.round($tools.math.div($pagination_nav_max,2)))##
    #set($pagination_nav_radius = $pagination_nav_mid - 1)##
    #set($shift = 0)##
    #set($pagination_nav_end = $count)##
    #set($showFirst = "false")##
    #set($showLast = "false")##
    #set($previous = $thispage - 1)##
    #set($next = $thispage + 1)##
	#set($last = $count)##
	#set($first = 1)
    ##
    #if($count > $pagination_nav_max)##
        ##
        #if($thispage <= $pagination_nav_mid)
            #set($showLast = "true")##
            #set($shift = 0)##
        #elseif ($thispage >= ($count - $pagination_nav_radius))##
            #set($shift = $count - $pagination_nav_max)##
            #set($showFirst = "true")##
        #else##
            #set($shift = $thispage - $pagination_nav_mid)##
            #set($showFirst = "true")##
            #set($showLast = "true")##
        #end## end if thispage <= pagination_nav_mid
        ##
        #set($pagination_nav_end = $pagination_nav_max + $shift)##
    #end## end if count > pagination_nav_max
    ##
    #set($pagination_nav_start = 1 + $shift)##
    #set($template = $sys.assemblyItem.Template.Name)##
    ##
    #if($count > 1)##
		#if($showFirst=="true")##
			<a href="$rx.location.generateToPage($sys.assemblyItem,$template,$first)"> ##
			$firstpage_markup</a> ##
		#end##
		#if($previous > 0)## 
			<a href="$rx.location.generateToPage($sys.assemblyItem,$template,$previous)"> ##
			$previous_markup</a> ##
		#end##
		#foreach($this_page_nav in [$pagination_nav_start..$pagination_nav_end])##
			#if($this_page_nav == $thispage)##
				$thispage ##
			#else##
				<a href="$rx.location.generateToPage($sys.assemblyItem,$template,$this_page_nav)">
				$this_page_nav</a> ##
			#end## end if this_page_nav == thispage
		#end## end foreach this_page_nav in...
		#if($next <= $count)##
			<a href="$rx.location.generateToPage($sys.assemblyItem,$template,$next)">##
			$next_markup</a>##
		#end##
		#if($showLast=="true")##
			<a href="$rx.location.generateToPage($sys.assemblyItem,$template,$last)"> ##
			$lastpage_markup</a> ##
		#end##
	#end## end if##
#end## end macro #vt_pager

And here’s the call to the macro if anyone needs it

#vt_pager($sys.pagecount $selectpage "First " "< " $pagetext " >" " Last")

Shane

Excellent! Thanks for posting a working version. Glad I could help.

I have implemented your code and it works good when I use the “Publish Now” functionality. How ever, when I add it to an incremental content list to refresh itself, I lose the correct links. It links every number to the first page. I am on 6.7 and below is the code I added to create the links. A second set of eyes would be appreciated:


$previous = $rx.location.generateToPage($sys.assemblyItem,$template,$previous)

Is the slot you are using listed as a “Contained Slot” on the template’s Slot tab? Auto Slots won’t get picked up by an incremental if they aren’t listed there.

-n

[QUOTE=woodypike;20721]I have implemented your code and it works good when I use the “Publish Now” functionality. How ever, when I add it to an incremental content list to refresh itself, I lose the correct links. It links every number to the first page. I am on 6.7 and below is the code I added to create the links. A second set of eyes would be appreciated:


$previous = $rx.location.generateToPage($sys.assemblyItem,$template,$previous)

[/QUOTE]