Skip to main content
BreakawayPaul
Inspiring
June 20, 2009
Question

Need help with local navigation - previous/next links

  • June 20, 2009
  • 1 reply
  • 366 views

My office has a convention where when we have a multi-page document, we do "previous" and "next" links to provide navigation between pages.  Also part of the convention is the file naming.  Basically, a multi-page document will have the pages named like this:

jreport1.cfm
jreport2.cfm
jreport3.cfm
jreport4.cfm

And so on.

With our new site redesign, I've decided to get fancier with the navigation.  I want to make it look something like this:

[ << Prev ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ Next >> ]

I have the CSS worked out, and I've figured out how to do the numbered links.  I'm using this:

<cfset thisfile = #GetFileFromPath(CGI.SCRIPT_NAME)#>
<cfset page = 1>
<cfset filter = #left(gettoken(thisfile,"1","."),len(gettoken(thisfile,"1",".")) -1)# & "*" & #gettoken(thisfile,"2",".")#>
<cfdirectory action="list" name="pages" directory="#ExpandPath(".")#" filter="#filter#">
<div id="localnav">
<ul>
<cfloop query="pages">
<cfoutput><li><a href="#pages.name#"<cfif #pages.name# eq #thisfile#> class="current"</cfif>>#page#</a></li></cfoutput>
<cfset page = #page# +1>
</cfloop>
</ul>
</div>

That basically gets the name of the current page, gets a list of other pages in the directory that match the wildcard "pagename*cfm", then makes an unordered list of them, applying a class to the current one.

What I can't make out how to do is get the Next and Previous pages.  I have an idea on how to do it, but it would be a bazillion lines of code.  I'm wondering if anyone has any ideas on how to do it properly.

    This topic has been closed for replies.

    1 reply

    BreakawayPaul
    Inspiring
    June 21, 2009

    Figured it out!