Perl style:

my $current_page_num = 2; my $num_pages = 6; if ($current_page_num > 1) { ...display link to page $current_page_num-1... } for my $page_num (1 .. $num_pages) { if ($page_num == $current_page_num) { ...display page number... } else { ...display link to page $page_num... } } if ($current_page_num < $num_pages) { ...display link to page $current_page_num+1... }

Or template style:
(Whitespace added for readability.)
(The template system I use looks at the class for commands.)

<a class="if::Selector.link_prev sub::href::Selector.link_prev" href="{page_link_next}" >&lt;&lt;Prev</a> <span class="page_selector_cell"> <span class="if::Selector.Page.is_current text::Selector.Page.page_num current-page" >{page num}</span> <a class="unless::Selector.Page.is_current sub::href::Selector.Page.link text::Selector.Page.page_num" href="{page_link}" >{page num}</a> </span> <a class="if::Selector.link_next sub::href::Selector.link_next" href="{page_link_next}" >Next&gt;gt;</a>

given

Selector.link_prev -> Link to prev page, if any. Selector.link_next -> Link to next page, if any. page_selector_cell -> Loops over all page nums, setting these: Selector.Page.is_current -> True if page_num is current page. Selector.Page.page_num -> Loop variable. Selector.Page.link -> Link to page page_num.

In reply to Re: Navigation script? by ikegami
in thread Navigation script? by bobafifi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.