From 6a7cb85d1d9dacf42d02f933bbba3196c446f364 Mon Sep 17 00:00:00 2001 From: Rudy Rigot Date: Mon, 30 Jun 2014 17:39:03 -0700 Subject: [PATCH] Pagination in index and search --- public_html/index.php | 8 +++-- public_html/search.php | 12 ++++++-- resources/config.php | 6 ++-- resources/templates/pagination.php | 48 ++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 resources/templates/pagination.php diff --git a/public_html/index.php b/public_html/index.php index d123d3d..22ddb32 100644 --- a/public_html/index.php +++ b/public_html/index.php @@ -2,9 +2,11 @@ require_once '../resources/config.php'; require_once(LIBRARIES_PATH . "/Prismic.php"); + $page = isset($_GET['page']) ? $_GET['page'] : 1; + try { $ctx = Prismic::context(); - $documents = $ctx->getApi()->forms()->everything->ref($ctx->getRef())->submit(); + $documents = $ctx->getApi()->forms()->everything->page($page)->ref($ctx->getRef())->submit(); } catch (Guzzle\Http\Exception\BadResponseException $e) { Prismic::handlePrismicException($e); } @@ -16,7 +18,7 @@ require_once(TEMPLATES_PATH . "/header.php"); ?> -
+
@@ -44,4 +46,6 @@ getApi()->forms()->everything->query($q)->ref($ctx->getRef())->submit(); + $page = isset($_GET['page']) ? $_GET['page'] : 1; + $documents = $ctx->getApi()->forms()->everything->query($q)->page($page)->ref($ctx->getRef())->submit(); } catch (Guzzle\Http\Exception\BadResponseException $e) { Prismic::handlePrismicException($e); } @@ -36,5 +37,10 @@

- Back to home + Back to home

+ + $q + ); if (isset($maybeRef)) { $parameters['ref'] = $maybeRef; } diff --git a/resources/templates/pagination.php b/resources/templates/pagination.php new file mode 100644 index 0000000..3ac387e --- /dev/null +++ b/resources/templates/pagination.php @@ -0,0 +1,48 @@ + + +getTotalPages()>1) { ?> + +
+ + + \ No newline at end of file