v2.5.2
Giriş yap

sayfalama işlemini geliştirmek

arco
747 defa görüntülendi

<php?
Sayfalama işlemi yapıyorum Sayfaları yazdıma kodum şu şekilde=
for($i = 1; $i<=$toplamSayfa;$i++)

                      {

if ($i==$sayfa) {
echo ' <li class="page-item active">
<span class="page-link">'.$i.'<span class="sr-only">(current)</span>
</span>';

                      } else {
                        echo ' <li class="page-item"><a class="page-link" href="my-posts.php?sayfa='.$i.'">'.$i.'</a></li>
                    </li>';
                      }
                    }

?>

ama ben sayfalamada hepsini birden değil şu şekil olsun istiyorum=
1-2-3-4-5.....10-11-12
gibi olsun istiyorum çünkü sayfa sayısı fazla olunca butonlar kalabalık olacak estetik bozulacak
makifgokce
1683 gün önce

Elimde eski bir kod var bende bi yerden bulmuştum.Kendine göre düzenleyip kulllan.

function pagination($current_page, $total_records, $total_pages, $page_url)
{
    $pagination = '';
    if($total_pages > 0 && $total_pages != 1 && $current_page <= $total_pages){ //verify total pages and current page number
        $pagination .= '<ul>';

        $right_links    = $current_page + 3;
        $previous       = $current_page - 1; //previous link
        $next           = $current_page + 1; //next link
        $first_link     = true; //boolean var to decide our first link

        if($current_page > 1){
			$previous_link = ($previous==0)?1:$previous;
            $pagination .= '<li class="pagination"><a href="'.$page_url.'?page=1">İlk</a></li>'; //first link
            $pagination .= '<li class="pagination"><a href="'.$page_url.'?page='.$previous_link.'">Önceki</a></li>'; //previous link
                for($i = ($current_page-2); $i < $current_page; $i++){ //Create left-hand side links
                    if($i > 0){
                        $pagination .= '<li class="pagination"><a href="'.$page_url.'?page='.$i.'">'.$i.'</a></li>';
                    }
                }
            $first_link = false; //set first link to false
        }

        if($first_link){ //if current active page is first link
            $pagination .= '<li class="active pagination">'.$current_page.'</li>';
        }elseif($current_page == $total_pages){ //if it's the last active link
            $pagination .= '<li class="active pagination">'.$current_page.'</li>';
        }else{ //regular current link
            $pagination .= '<li class="active pagination">'.$current_page.'</li>';
        }

        for($i = $current_page+1; $i < $right_links ; $i++){ //create right-hand side links
            if($i<=$total_pages){
                $pagination .= '<li class="pagination"><a href="'.$page_url.'?page='.$i.'">'.$i.'</a></li>';
            }
        }
        if($current_page < $total_pages){
				$next_link = ($next > $total_pages)? $total_pages : $next;
                $pagination .= '<li class="pagination"><a href="'.$page_url.'?page='.$next_link.'">İleri</a></li>'; //next link
                $pagination .= '<li class="pagination"><a href="'.$page_url.'?page='.$total_pages.'">Son</a></li>'; //last link
        }

        $pagination .= '</ul>';
    }
    return $pagination; //return pagination links
}