pager
This commit is contained in:
parent
cbdfeb6a6c
commit
a72c8a0376
31
index.php
31
index.php
|
@ -18,6 +18,7 @@ if ($page > $numberOfPages) {
|
|||
}
|
||||
|
||||
$projects = getProjects($page, $limit);
|
||||
$pager = getProjectsPager($page, $numberOfPages);
|
||||
|
||||
?>
|
||||
<!DOCTYPE HTML>
|
||||
|
@ -32,6 +33,18 @@ $projects = getProjects($page, $limit);
|
|||
<body>
|
||||
<h1>Mon super portfolio</h1>
|
||||
|
||||
<?php if (count($pager) > 1): ?>
|
||||
<ul class="pager">
|
||||
<?php foreach ($pager as $p): ?>
|
||||
<li <?php if ($p['current'] === true): ?>class="active"<?php endif ?>>
|
||||
<a href="?page=<?php echo $p['page'] ?>">
|
||||
<?php echo $p['title'] ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
|
||||
<section>
|
||||
<?php foreach($projects as $project): ?>
|
||||
<article>
|
||||
|
@ -60,12 +73,16 @@ $projects = getProjects($page, $limit);
|
|||
<?php endforeach ?>
|
||||
</section>
|
||||
|
||||
<!--
|
||||
Générer la pagination :
|
||||
|
||||
Première page | Précédent | 1 | 2 | 3 ... | Suivant | Dernière page
|
||||
|
||||
Mettre en avant la page courrante
|
||||
-->
|
||||
<?php if (count($pager) > 1): ?>
|
||||
<ul class="pager">
|
||||
<?php foreach ($pager as $p): ?>
|
||||
<li <?php if ($p['current'] === true): ?>class="active"<?php endif ?>>
|
||||
<a href="?page=<?php echo $p['page'] ?>">
|
||||
<?php echo $p['title'] ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -87,3 +87,56 @@ function getCommentsByProject($id)
|
|||
}
|
||||
|
||||
// Prévoir une fonction pour enregistrer un commentaire
|
||||
|
||||
function getProjectsPager($page, $numberOfPages)
|
||||
{
|
||||
$pages = [];
|
||||
|
||||
if ($numberOfPages > 1) {
|
||||
$pages[] = array(
|
||||
'title' => 'Première page',
|
||||
'page' => 1,
|
||||
'current' => $page === 1,
|
||||
);
|
||||
}
|
||||
|
||||
if ($page > 1) {
|
||||
$pages[] = array(
|
||||
'title' => 'Précédent',
|
||||
'page' => $page - 1,
|
||||
'current' => false,
|
||||
);
|
||||
}
|
||||
|
||||
if ($numberOfPages > 1) {
|
||||
for ($i = 1; $i <= $numberOfPages; $i++) {
|
||||
$pages[] = array(
|
||||
'title' => $i,
|
||||
'page' => $i,
|
||||
'current' => $page === $i,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($page < $numberOfPages) {
|
||||
$pages[] = array(
|
||||
'title' => 'Suivant',
|
||||
'page' => $page + 1,
|
||||
'current' => false,
|
||||
);
|
||||
}
|
||||
|
||||
if ($numberOfPages > 1) {
|
||||
$pages[] = array(
|
||||
'title' => 'Dernière page',
|
||||
'page' => $numberOfPages,
|
||||
'current' => $page === $numberOfPages,
|
||||
);
|
||||
}
|
||||
|
||||
return $pages;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue