This commit is contained in:
Simon Vieille 2016-01-28 10:26:50 +01:00
parent cbdfeb6a6c
commit a72c8a0376
3 changed files with 90 additions and 7 deletions

View File

@ -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>

View File

@ -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;
}

View File

@ -32,3 +32,16 @@ figure {
.description {
padding-left: 150px;
}
.pager li {
display: inline;
}
.pager .active {
font-weight: bold;
}
.pager a {
text-decoration: none;
color: #000;
}