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);
|
$projects = getProjects($page, $limit);
|
||||||
|
$pager = getProjectsPager($page, $numberOfPages);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE HTML>
|
<!DOCTYPE HTML>
|
||||||
|
@ -31,6 +32,18 @@ $projects = getProjects($page, $limit);
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Mon super portfolio</h1>
|
<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>
|
<section>
|
||||||
<?php foreach($projects as $project): ?>
|
<?php foreach($projects as $project): ?>
|
||||||
|
@ -60,12 +73,16 @@ $projects = getProjects($page, $limit);
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<!--
|
<?php if (count($pager) > 1): ?>
|
||||||
Générer la pagination :
|
<ul class="pager">
|
||||||
|
<?php foreach ($pager as $p): ?>
|
||||||
Première page | Précédent | 1 | 2 | 3 ... | Suivant | Dernière page
|
<li <?php if ($p['current'] === true): ?>class="active"<?php endif ?>>
|
||||||
|
<a href="?page=<?php echo $p['page'] ?>">
|
||||||
Mettre en avant la page courrante
|
<?php echo $p['title'] ?>
|
||||||
-->
|
</a>
|
||||||
|
</li>
|
||||||
|
<?php endforeach ?>
|
||||||
|
</ul>
|
||||||
|
<?php endif ?>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -87,3 +87,56 @@ function getCommentsByProject($id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prévoir une fonction pour enregistrer un commentaire
|
// 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