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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:36:53+00:00 2026-05-14T20:36:53+00:00

I have the following method that creates and returns markup for my pagination links

  • 0

I have the following method that creates and returns markup for my pagination links in PHP.

public function getPaginationLinks($options) {
    if($options['total_pages'] > 1) {
        $markup = '<div class="pagination">';

        if($options['page'] > 1) {
            $markup .= '<a href="?page=' . ($options['page'] - 1) . ((isset($options['order_by'])) ? "&sort=" . $options['order_by'] : "") . '">< prev</a>';
        }       

        for($i = 1; $i <= $options['total_pages']; $i++) {

            if($options['page'] != $i) {
                $markup .= '<a href="?page='. $i . ((isset($options['order_by'])) ? "&sort=" . $options['order_by'] : "") . '">' . $i . '</a>';
            }
            else {
                $markup .= '<span class="current">' . $i . '</span>';
            }
        }

        if($options['page'] < $options['total_pages']) {
            $markup .= '<a href="?page=' . ($options['page'] + 1) . ((isset($options['order_by'])) ? "&sort=" . $options['order_by'] : "") . '">next ></a>';
        }

        $markup .= '</div>';

        return $markup;
    }
    else {
        return false;
    }
}

I just recently discovered (to my surprise) that i had reached 70+ pages which means that there are now 70+ links showing up at the bottom..

I’m wondering if someone can help me break this up.. I’m not sure how most pagination works as far as showing the numbers if im on say.. page 30, ideas?

  • 1 1 Answer
  • 1 View
  • 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-14T20:36:54+00:00Added an answer on May 14, 2026 at 8:36 pm

    You just display the current page plus the previous and the following x (say 4) pages.

    If you’re on Page 1:

    1 2 3 4 5
    

    Page 35:

    31 32 33 34 35 36 37 38 39
    

    Page 70:

    66 67 68 69 70
    

    You could also add a quick link to the first and last page using « and » for instance.


    Example:

    $x = 4;
    
    for ($i = $currentPage - $x; $i < $currentPage; $i++)
    {
        if ($i >= 1) { /* show link */}
        else { /* show ellipsis and fix counter */ $i = 1; }
    }
    
    /* show current page number without link */
    
    for ($i = $currentPage + 1; $i < $currentPage + $x; $i++)
    {
        if ($i <= $totalPages) { /* show link */}
        else { /* show ellipsis and break */ break; }
    }
    

    You can also implement Infinite History / Pagination, which is uber cool. =)


    UPDATE: A more elegant version of this @ Codepad.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that contains the following (Java) code: doSomeThings(); doSomeOtherThings(); doSomeThings() creates
I have an interface (called Subject ) that has the following method: public void
I have the following JNI method that creates a collection of Java objects natively,
I have the following method GetData that creates a StreamReader from a file. private
I have the following method that is replacing a pound sign from the file
I have the following method that is supposed to be a generic Save to
I have a method that I will use in the following contexts: 1. User
I have a program that makes use of the following method to get a
I have a simple mapview that has the following viewdidload method and didupdate to
I have the following method which returns the local declared Object by value: Human

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.