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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:29:53+00:00 2026-06-16T19:29:53+00:00

I am currently using a pagination script that uses a class named pagination. I

  • 0

I am currently using a pagination script that uses a class named “pagination”. I would like to duplicate this class in another file to use it again. I’m having problems with my framework recognizing it as “duplicate”. I know that changing it should be as simple as changing the class name, but there are several functions within the class that makes it too complex for me to figure out.

So my question is, based on the code below, what variables, functions, values, etc. would I need to change in my class in order to create an identical copy of it?

class pagination {
/*
   Script Name: *Digg Style Paginator Class
   Script URI: http://www.mis-algoritmos.com/2007/05/27/digg-style-pagination-class/
   Description: Class in PHP that allows to use a pagination like a digg or sabrosus style.
   Script Version: 0.4
   Author: Victor De la Rocha
   Author URI: http://www.mis-algoritmos.com
*/
/*Default values*/
var $total_pages    = - 1; //items
var $limit          = null;
var $target         = "";
var $page           = 1;
var $adjacents      = 2;
var $showCounter    = false;
var $className      = "pagination";
var $parameterName  = "pg";
var $urlF           = false; //urlFriendly
/*Buttons next and previous*/
var $nextT          = "Next";
var $nextI          = "»"; //►
var $prevT          = "Previous";
var $prevI          = "«"; //◄

var $calculate      = false;
// Total items
function items($value) {
    $this->total_pages  = (int) $value;
}
// how many items to show per page
function limit($value) {
    $this->limit        = (int) $value;
}
// Page to sent the page value
function target($value) {
    $this->target       = $value;
}
// Current page
function currentPage($value) {
    $this->page         = (int) $value;
}
// How many adjacent pages should be shown on each side of the current page?
function adjacents($value) {
    $this->adjacents    = (int) $value;
}
// show counter?
function showCounter($value = "") {
    $this->showCounter  = ($value === true)?true:false;
}
// to change the class name of the pagination div
function changeClass($value = "") {
    $this->className    = $value;
}

function nextLabel($value) {
    $this->nextT        = $value;
}
function nextIcon($value) {
    $this->nextI        = $value;
}
function prevLabel($value) {
    $this->prevT        = $value;
}
function prevIcon($value) {
    $this->prevI        = $value;
}
// to change the class name of the pagination div
function parameterName($value = "") {
    $this->parameterName = $value;
}
// to change urlFriendly
function urlFriendly($value = "%") {
    if (eregi('^ *$', $value)) {
        $this->urlF = false;
        return false;
    }
    $this->urlF = $value;
}

var $pagination;
function pagination() {
}
function show() {
    if (!$this->calculate) {
        if ($this->calculate()) {
            echo "<div class=\"$this->className\">$this->pagination</div>\n";
        }
    }
}
function getOutput() {
    if (!$this->calculate) {
        if ($this->calculate()) {
            return "<div class=\"$this->className\">$this->pagination</div>\n";
        }
    }
}
function get_pagenum_link($id) {
    if (strpos($this->target, '?') === false)
        if ($this->urlF)
            return str_replace($this->urlF, $id, $this->target);
        else
            return "$this->target?$this->parameterName=$id";
    else
        return "$this->target&$this->parameterName=$id";
}

function calculate() {
    $this->pagination = "";
    $this->calculate == true;
    $error = false;
    if ($this->urlF and $this->urlF != '%' and strpos($this->target, $this->urlF) === false) {
        // Es necesario especificar el comodin para sustituir
        echo "Especificaste un wildcard para sustituir, pero no existe en el target<br />";
        $error = true;
    } elseif ($this->urlF and $this->urlF == '%' and strpos($this->target, $this->urlF) === false) {
        echo "Es necesario especificar en el target el comodin % para sustituir el n?mero de p?gina<br />";
        $error = true;
    }

    if ($this->total_pages <0) {
        echo "It is necessary to specify the <strong>number of pages</strong> (\$class->items(1000))<br />";
        $error = true;
    }
    if ($this->limit == null) {
        echo "It is necessary to specify the <strong>limit of items</strong> to show per page (\$class->limit(10))<br />";
        $error = true;
    }
    if ($error)return false;

    $n = trim($this->nextT . ' ' . $this->nextI);
    $p = trim($this->prevI . ' ' . $this->prevT);

    /* Setup vars for query. */
    if ($this->page)
        $start = ($this->page - 1) * $this->limit; //first item to display on this page
    else
        $start = 0; //if no page var is given, set start to 0
    /* Setup page vars for display. */
    $prev = $this->page - 1; //previous page is page - 1
    $next = $this->page + 1; //next page is page + 1
    $lastpage = ceil($this->total_pages / $this->limit); //lastpage is = total pages / items per page, rounded up.
    $lpm1 = $lastpage - 1; //last page minus 1
    /*
       Now we apply our rules and draw the pagination object.
       We're actually saving the code to a variable in case we want to draw it more than once.
    */

    if ($lastpage > 1) {
        if ($this->page) {
            // anterior button
            if ($this->page > 1)
                $this->pagination .= "<a href=\"" . $this->get_pagenum_link($prev) . "\" class=\"prev\">$p</a>";
            else
                $this->pagination .= "<span class=\"disabled\">$p</span>";
        }
        // pages
        if ($lastpage <7 + ($this->adjacents * 2)) { // not enough pages to bother breaking it up
            for ($counter = 1; $counter <= $lastpage; $counter++) {
                if ($counter == $this->page)
                    $this->pagination .= "<span class=\"current\">$counter</span>";
                else
                    $this->pagination .= "<a href=\"" . $this->get_pagenum_link($counter) . "\">$counter</a>";
            }
        } elseif ($lastpage > 5 + ($this->adjacents * 2)) { // enough pages to hide some
            // close to beginning; only hide later pages
            if ($this->page <1 + ($this->adjacents * 2)) {
                for ($counter = 1; $counter <4 + ($this->adjacents * 2); $counter++) {
                    if ($counter == $this->page)
                        $this->pagination .= "<span class=\"current\">$counter</span>";
                    else
                        $this->pagination .= "<a href=\"" . $this->get_pagenum_link($counter) . "\">$counter</a>";
                }
                $this->pagination .= "...";
                $this->pagination .= "<a href=\"" . $this->get_pagenum_link($lpm1) . "\">$lpm1</a>";
                $this->pagination .= "<a href=\"" . $this->get_pagenum_link($lastpage) . "\">$lastpage</a>";
            }
            // in middle; hide some front and some back
            elseif ($lastpage - ($this->adjacents * 2) > $this->page && $this->page > ($this->adjacents * 2)) {
                $this->pagination .= "<a href=\"" . $this->get_pagenum_link(1) . "\">1</a>";
                $this->pagination .= "<a href=\"" . $this->get_pagenum_link(2) . "\">2</a>";
                $this->pagination .= "...";
                for ($counter = $this->page - $this->adjacents; $counter <= $this->page + $this->adjacents; $counter++)
                    if ($counter == $this->page)
                        $this->pagination .= "<span class=\"current\">$counter</span>";
                    else
                        $this->pagination .= "<a href=\"" . $this->get_pagenum_link($counter) . "\">$counter</a>";
                $this->pagination .= "...";
                $this->pagination .= "<a href=\"" . $this->get_pagenum_link($lpm1) . "\">$lpm1</a>";
                $this->pagination .= "<a href=\"" . $this->get_pagenum_link($lastpage) . "\">$lastpage</a>";
            }
            // close to end; only hide early pages
            else {
                $this->pagination .= "<a href=\"" . $this->get_pagenum_link(1) . "\">1</a>";
                $this->pagination .= "<a href=\"" . $this->get_pagenum_link(2) . "\">2</a>";
                $this->pagination .= "...";
                for ($counter = $lastpage - (2 + ($this->adjacents * 2)); $counter <= $lastpage; $counter++)
                    if ($counter == $this->page)
                        $this->pagination .= "<span class=\"current\">$counter</span>";
                    else
                        $this->pagination .= "<a href=\"" . $this->get_pagenum_link($counter) . "\">$counter</a>";
            }
        }
        if ($this->page) {
            // siguiente button
            if ($this->page <$counter - 1)
                $this->pagination .= "<a href=\"" . $this->get_pagenum_link($next) . "\" class=\"next\">$n</a>";
            else
                $this->pagination .= "<span class=\"disabled\">$n</span>";
            if ($this->showCounter)$this->pagination .= "<div class=\"pagination_data\">($this->total_pages Pages)</div>";
        }
    }

    return true;
}
}

?>
  • 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-06-16T19:29:54+00:00Added an answer on June 16, 2026 at 7:29 pm

    Try to include the file which holds the pagination class only once!

    Use incldue_once or require_once instead of include and require.

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

Sidebar

Related Questions

I am currently using displaytag for tabular data, but would like to create a
Hey, i am currently creating a pagination script using php and jquery and for
I'm using Recent products shortcode, [recent_products per_page=4 columns=2] and would like to have pagination,
I am using a gridview that uses image pagenation. This seems to perform a
I am currently coding a pagination script into many parts of my site, this
Currently using the HTTPServletRequest class and specifically the .getQueryString method to retrieve an inputted
Currently using MySQL version 5.1.6 This is my first real world build and so
I currently have pagination working in my MVC 3 project using the PagedList library
I am intending to implement pagination in a tableview. Currently, I am using the
Currently working on something which uses ajax for some pagination. What I'm looking to

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.