Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6047829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:23:42+00:00 2026-05-23T07:23:42+00:00

p – is request parameter where the page number is given by user <#assign

  • 0
 p - is request parameter where the page number is given by user

<#assign totalPages =searchResult.getTotalPages()>
<#assign lastPage = 0>

<#list totalPages as curPage>
    <#if p=curPage>
         <a href="#" class="selected">${p}</a>
         <#assign lastPage = curPage?number>
    <#else>
         <a href="/search.html?q=${q?html}&amp;p=${curPage}">${curPage}</a>
    </#if>
</#list>

This will print links like this

1 2 3 4 5 6 7 8 9 10 11 - and the list keeps going to the last page lets say 100

What I would like to accomplish is these cases (number in <x> is the p – page selected by user):

Case A: 
1 <2> 3 4 5 ... 100

Case B:
1 ... 11 12 <13> 14 15 ... 100

Case C:
1 ... <96> 97 98 99 100

Any ideas on how to do this in the above freemarker code? Pseudo code is fine too.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:23:43+00:00Added an answer on May 23, 2026 at 7:23 am

    Here are two helper functions max and min and a macro I called pages:

    <#function max x y>
        <#if (x<y)><#return y><#else><#return x></#if>
    </#function>
    <#function min x y>
        <#if (x<y)><#return x><#else><#return y></#if>
    </#function>
    <#macro pages totalPages p>
        <#assign size = totalPages?size>
        <#if (p<=5)> <#-- p among first 5 pages -->
            <#assign interval = 1..(min(5,size))>
        <#elseif ((size-p)<5)> <#-- p among last 5 pages -->
            <#assign interval = (max(1,(size-4)))..size >
        <#else>
            <#assign interval = (p-2)..(p+2)>
        </#if>
        <#if !(interval?seq_contains(1))>
         1 ... <#rt>
        </#if>
        <#list interval as page>
            <#if page=p>
             <${page}> <#t>
            <#else>
             ${page} <#t>
            </#if>
        </#list>
        <#if !(interval?seq_contains(size))>
         ... ${size}<#lt>
        </#if>
    </#macro>
    

    This macro produces, when invoked with a sequence of page numbers and the current page, e.g.

    <@pages 1..100 2 />
    <@pages 1..100 13 />
    <@pages 1..100 96 />
    <@pages 1..3 2 />
    

    the following output (removed some whitespaces):

    1 <2> 3 4 5 ... 100
    1 ... 11 12 <13> 14 15 ... 100
    1 ... <96> 97 98 99 100 
    1 <2> 3 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My NSXMLParser breaks on this string: <title>AAA &#8211; BCDEFGQWERTYUIO</title> I parsed it in this
I need to clean up various Word 'smart' characters in user input, including but
I would like to count the length of a string with PHP. The string
I've got the following login script.. <?php $name = $_POST[name]; $password = $_POST[password]; $query
So to start, I have an array of XML files. These files need to
I'm struggling to position the second level of a dropdown nav menu and was
Have a webpage that will be viewed by mainly IE users, so CSS3 is
I'm trying to craft a Java regular expression to split strings of the general
I am currently running into a problem where an element is coming back from
i have this code: <?php $valid_ext = array(pdf, doc); $args = array( 'post_type' =>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.