From a72c8a0376892967317bee74dbd5493389301915 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 28 Jan 2016 10:26:50 +0100 Subject: [PATCH] pager --- index.php | 31 ++++++++++++++++++++++------- lib/project.php | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ style.css | 13 ++++++++++++ 3 files changed, 90 insertions(+), 7 deletions(-) diff --git a/index.php b/index.php index d7b14a0..d0d420f 100644 --- a/index.php +++ b/index.php @@ -18,6 +18,7 @@ if ($page > $numberOfPages) { } $projects = getProjects($page, $limit); +$pager = getProjectsPager($page, $numberOfPages); ?> @@ -31,6 +32,18 @@ $projects = getProjects($page, $limit);

Mon super portfolio

+ + 1): ?> + +
@@ -60,12 +73,16 @@ $projects = getProjects($page, $limit);
- + 1): ?> + + diff --git a/lib/project.php b/lib/project.php index c3d7eb1..e8ca80d 100644 --- a/lib/project.php +++ b/lib/project.php @@ -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; +} + + + + diff --git a/style.css b/style.css index 39e0bb1..61d4ff6 100644 --- a/style.css +++ b/style.css @@ -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; +}