Last active
January 7, 2024 03:32
-
-
Save ahmeti/84c071725354dc17649d8860d28f8671 to your computer and use it in GitHub Desktop.
ahmeti.com.tr - Php ile Kolayca Sayfalama Yapmak
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// $top_sayfa == Toplam Sayfa Sayısı | |
// $page == Mevcut Sayfa | |
// $limit == Sayfa Limiti | |
// $page_url == Sayfa Bağlantısı | |
function Sayfala($top_sayfa, $page, $limit, $page_url) | |
{ | |
// Sayfalama Şeridimiz | |
if ($top_sayfa > $limit) { | |
echo '<div id="sayfala"><span class="say_sabit">Sayfalar</span>'; | |
$x = 5; // Aktif sayfadan önceki/sonraki sayfa gösterim sayisi | |
$lastP = ceil($top_sayfa / $limit); | |
// sayfa 1'i yazdir | |
if ($page == 1) { | |
echo '<span class="say_aktif">1</span>'; | |
} else { | |
echo '<a class="say_a" href="https://ahmeti.com.tr/'.$page_url.'">1</a>'; | |
} | |
// "..." veya direkt 2 | |
if ($page - $x > 2) { | |
echo '<span class="say_b">...</span>'; | |
$i = $page - $x; | |
} else { | |
$i = 2; | |
} | |
// +/- $x sayfalari yazdir | |
for ($i; $i <= $page + $x; $i++) { | |
if ($i == $page) { | |
echo '<span class="say_aktif">'.$i.'</span>'; | |
} else { | |
echo '<a class="say_a" href="https://ahmeti.com.tr/'.$page_url.'&page='.$i.'">'.$i.'</a>'; | |
} | |
if ($i == $lastP) { | |
break; | |
} | |
} | |
// "..." veya son sayfa | |
if ($page + $x < $lastP - 1) { | |
echo '<span class="say_b">...</span>'; | |
echo '<a class="say_a" href="https://ahmeti.com.tr/'.$page_url.'&page='.$lastP.'">'.$lastP.'</a>'; | |
} elseif ($page + $x == $lastP - 1) { | |
echo '<a class="say_a" href="https://ahmeti.com.tr/'.$page_url.'&page='.$lastP.'">'.$lastP.'</a>'; | |
} | |
echo '</div>'; //#sayfala | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#sayfala { | |
overflow: hidden; | |
width: 960px; | |
height: 30px; | |
padding-top: 10px | |
} | |
#sayfala a { | |
text-decoration: none | |
} | |
.say_a { | |
float: left; | |
margin-right: 5px; | |
border: 1px solid #94A3C4; | |
padding: 5px 0; | |
text-align: center; | |
width: 25px | |
} | |
.say_a:hover { | |
background-color: #FADADC; | |
color: #000 | |
} | |
.say_b { | |
float: left; | |
margin-right: 5px; | |
padding: 6px 0; | |
text-align: center; | |
width: 15px | |
} | |
.say_aktif { | |
float: left; | |
margin-right: 5px; | |
border: 1px solid #94A3C4; | |
padding: 5px 0; | |
text-align: center; | |
background-color: #CFF; | |
width: 25px; | |
} | |
.say_sabit { | |
float: left; | |
margin-right: 5px; | |
border: 1px solid #94A3C4; | |
padding: 5px 0; | |
text-align: center; | |
background-color: #CFF; | |
width: 70px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment