1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Paging like digg.com

Discussion in 'PHP' started by varun8211, May 28, 2007.

  1. #1
    Does anybody have the script for the paging like in Digg.com ?
    1 2 3 .... 10 11 etc .

    Is it the CSS/Javascript ?

    design of those boxes of the page numbers is very nice and clean.. similar on digital point..
     
    varun8211, May 28, 2007 IP
  2. manilodisan

    manilodisan Peon

    Messages:
    224
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you're looking for a pagination script or just css?
     
    manilodisan, May 28, 2007 IP
  3. varun8211

    varun8211 Peon

    Messages:
    483
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    both.. paging script as well as that cSS.

    paging needs to be similar to digg
    eg 1 2 .... 10 11..... 20 21
     
    varun8211, May 28, 2007 IP
  4. gigidawg

    gigidawg Peon

    Messages:
    380
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I noticed ebaumsworld.com is using the same pagination buttons, and also wordpress codex. Im guessing theres a plugin somewhere, if you find it please let me know as well.
     
    gigidawg, May 28, 2007 IP
  5. manilodisan

    manilodisan Peon

    Messages:
    224
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    <?php
    
    class CI_Pagination {
        
        var $limit = 10;                                // how many per page
        var $select_what = '*';                         // what to select
        var $add_query = '';
        var $otherParams = '';
        /* customize links */
        var $first_r = 'FIRST';
        var $next_r  = '&gt;';
        var $previous_r = '&lt;';
        var $last_r = 'LAST';
        
        function getQuery($return_q=FALSE)
        {
            
            $query = mysql_query('SELECT SQL_CALC_FOUND_ROWS '.$this->select_what.''
                   . ' FROM '.$this->the_table.' '.$this->add_query.''
                   . ' LIMIT '.$this->start.', '.$this->limit.'');
                   
            $nbItems = mysql_result(mysql_query('SELECT FOUND_ROWS() AS nbr'), 0, 'nbr');
            if($nbItems > ($this->start + $this->limit))
            {
                $final = $this->start + $this->limit;
            }
            else {
                $final = $nbItems;
            }
            if($return_q==FALSE)
            {
                return $nbItems;
            }
            else {
                return $query;
            }
        }
        
        
        function paginate() {
    
                $nbItems = CI_Pagination::getQuery(FALSE);
                
                if($nbItems<=$this->limit)
                {
                    return;
                }
                else {
                
                    $allPages = ceil($nbItems/$this->limit);
                
                    $currentPage = floor($this->start/$this->limit) + 1;
                
                    $pagination = "";
                    if ($allPages>10) {
                        $maxPages = ($allPages>9) ? 9 : $allPages;
                
                        if ($allPages>9) {
                            if ($currentPage>=1&&$currentPage<=$allPages) {
                                $pagination .= ($currentPage>4) ? " ... " : " ";
                
                                $minPages = ($currentPage>4) ? $currentPage : 5;
                                $maxPages = ($currentPage<$allPages-4) ? $currentPage : $allPages - 4;
                
                                for($i=$minPages-4; $i<$maxPages+5; $i++) {
                                    $pagination .= ($i == $currentPage) ? "<a href=\"#\" class=\"current\">".$i."</a> " : "<a href=\"".$this->filePath."/".(($i-1)*$this->limit).$this->otherParams."\">".$i."</a> ";
                                }
                                $pagination .= ($currentPage<$allPages-4) ? " ... " : " ";
                            } else {
                                $pagination .= " ... ";
                            }
                        }
                    } else {
                        for($i=1; $i<$allPages+1; $i++) {
                            $pagination .= ($i==$currentPage) ? "<a href=\"#\" class=\"current\">".$i."</a> " : "<a href=\"".$this->filePath."/".(($i-1)*$this->limit).$this->otherParams."\">".$i."</a> ";
                        }
                    }
                
                    if ($currentPage>1)
                    {
                        $pagination = "<a href=\"".$this->filePath."/0".$this->otherParams."\">".$this->first_r."</a>"
                                    . " <a href=\"".$this->filePath."/".(($currentPage-2)*$this->limit).$this->otherParams."\">"
                                    . "".$this->previous_r."</a> ".$pagination;
                    }
                    if ($currentPage<$allPages)
                    {
                        $pagination .= "<a href=\"".$this->filePath."/".($currentPage*$this->limit).$this->otherParams."\">"
                                     . "".$this->next_r."</a> <a href=\"".$this->filePath."/".(($allPages-1)*$this->limit).$this->otherParams."\">"
                                     . "".$this->last_r."</a>";
                    }
            
                return '<div class="pages">' . $pagination . '</div>';
            }
        }
        
    }
    ?>
    
    PHP:
     
    manilodisan, May 28, 2007 IP
  6. manilodisan

    manilodisan Peon

    Messages:
    224
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    
    include('pagination.php');
    $obj = new CI_Pagination();
    
    $obj->start = $_GET['start'];
    $obj->filePath = site_url('listings/show_listings/'.$cat_id);
    $obj->select_what = 'ID';
    $obj->the_table = 'mytable';
    $obj->add_query = 'WHERE category = '.$category.' AND active=1 ORDER BY ID DESC';
    $query = $obj->getQuery(TRUE);
    PHP:
     
    manilodisan, May 28, 2007 IP
  7. manilodisan

    manilodisan Peon

    Messages:
    224
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    div.pages div, div.pages a {
        margin-right: 1px;
        padding: 1px 5px 2px 5px;
        border: 1px solid #999;
        text-decoration: none;
        font-size: 12px;
        color: #999;
    }
    div.pages div, div.pages a:hover {
        border: 1px solid #999;
        background-color:#d7d7d7;
        color:#fff;
    }
    div.pages .current {
        border: 1px solid #999;
        background-color:#d8d8d8;
    } 
    PHP:
    link example for pagination: article.php?ID=1&start=0 - where 0 is the start number from where should the pagination start.

    For more pagination examples use this link
    Here's an example with the result (scroll down to the bottom - hope it helps).
     
    manilodisan, May 28, 2007 IP
  8. samusexu

    samusexu Well-Known Member

    Messages:
    138
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #8
    Varun, you can also use PEAR::pager, it's a nice package that can support a lot of features like ajax or mod_rewrite.
     
    samusexu, May 28, 2007 IP