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 7528277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:20:03+00:00 2026-05-30T04:20:03+00:00

Though this question has been asked several times but I really couldn’t find any

  • 0

Though this question has been asked several times but I really couldn’t find any clue from it.

I am working on a client project in which the page numbers are generated like this:

[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] and so on …

So if there are 100 pages, these numbers will count to … [100].

Here is the code that I am using:

{foreach var=$page from=$pages counter=$counter}
<li><a href="$page.page_url">$counter</a>
{/foreach}

I am looking to paginate them such that at most only 10 pages numbers are displayed per page.

Any help will be highly appreciate.

Thanks in advance.

  • 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-30T04:20:04+00:00Added an answer on May 30, 2026 at 4:20 am

    First you have to remember page number of the current page. Then decide about the behavior of the pagination. Example current page, next four pages, three previous pages, first page and last page

    So for page nr 9 it looks like this:
    [1] … [6] [7] [8] [bold 9] [10] [11] [12] [13] … [100]

    Next (hardest) thing is defining an efficient algorithm.

    For example:

    1. Define an empty list
    2. Put current page on the list.
    3. Add desired amount of elements before the current page (for example first element and m elements to the left of the current page)
    4. Add desired amount of elements after the current page (for example n elements to the right of the page and the last element)
    5. Iterate over the list to produce the pagination.

    Iteration example:

    foreach element on list:
        if element.value == current_page
            print_bold [element.value]
        else
            print [element.value]
        nextElement = list.nextElement
        if nextElement.value - element.value > 1:
            print "..."
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has been asked several times, but I can't quite seem
Apologies if this question has been asked. I couldn't find it, but if it
I know this question has been asked before, but no one has given any
I know this question has been asked many times, but I am having trouble
First, I know this question has been asked several times before and that in
This is a variation on a question that has been asked here several times.
Folks, I know this question has been asked before here, though indirectly . But
A question like this has been asked differently several times. Yet here i am.
I know this has been asked several times, but the problem is they bring
I know this question has been asked 100x but I can't seem to find

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.