From 4d260b6fe5a30b3633b06c2175c2124ef1b97c27 Mon Sep 17 00:00:00 2001
From: Marcin Kurczewski <mkurczew@gmail.com>
Date: Sun, 13 Oct 2013 22:09:52 +0200
Subject: [PATCH] Fixed pagination when no pages should be shown

---
 src/Views/post-list.phtml | 82 ++++++++++++++++++++-------------------
 1 file changed, 42 insertions(+), 40 deletions(-)

diff --git a/src/Views/post-list.phtml b/src/Views/post-list.phtml
index 912cf9b6..7c539ecf 100644
--- a/src/Views/post-list.phtml
+++ b/src/Views/post-list.phtml
@@ -31,49 +31,51 @@ if (!function_exists('pageUrl'))
 }
 ?>
 
-<nav class="paginator-wrapper">
-	<ul class="paginator">
-		<?php if ($this->context->transport->page > 1): ?>
-			<li class="prev">
-		<?php else: ?>
-			<li class="prev inactive">
-		<?php endif ?>
-			<a href="<?php echo pageUrl($this->context->transport->page - 1) ?>">
-				&laquo;
-			</a>
-		</li>
+<?php
+	$pagesVisible = [];
+	$pagesVisible []= 1;
+	$pagesVisible []= $this->context->transport->pageCount;
+	$delta = 3;
+	$pagesVisible = array_merge($pagesVisible, range($this->context->transport->page - $delta, $this->context->transport->page + $delta));
+	$pagesVisible = array_filter($pagesVisible, function($x) { return $x >= 1 and $x <= $this->context->transport->pageCount; });
+	$pagesVisible = array_unique($pagesVisible);
+	sort($pagesVisible, SORT_NUMERIC);
+?>
 
-		<?php
-			$pagesVisible = [];
-			$pagesVisible []= 1;
-			$pagesVisible []= $this->context->transport->pageCount;
-			$delta = 3;
-			$pagesVisible = array_merge($pagesVisible, range($this->context->transport->page - $delta, $this->context->transport->page + $delta));
-			$pagesVisible = array_filter($pagesVisible, function($x) { return $x >= 1 and $x <= $this->context->transport->pageCount; });
-			$pagesVisible = array_unique($pagesVisible);
-			sort($pagesVisible, SORT_NUMERIC);
-		?>
-
-		<?php foreach ($pagesVisible as $page): ?>
-			<?php if ($page == $this->context->transport->page): ?>
-				<li class="active">
+<?php if (!empty($pagesVisible)): ?>
+	<nav class="paginator-wrapper">
+		<ul class="paginator">
+			<?php if ($this->context->transport->page > 1): ?>
+				<li class="prev">
 			<?php else: ?>
-				<li>
+				<li class="prev inactive">
 			<?php endif ?>
-				<a href="<?php echo pageUrl($page) ?>">
-					<?php echo $page ?>
+				<a href="<?php echo pageUrl($this->context->transport->page - 1) ?>">
+					&laquo;
 				</a>
 			</li>
-		<?php endforeach ?>
 
-		<?php if ($this->context->transport->page < $this->context->transport->pageCount): ?>
-			<li class="next">
-		<?php else: ?>
-			<li class="next inactive">
-		<?php endif ?>
-			<a href="<?php echo pageUrl($this->context->transport->page + 1) ?>">
-				&raquo;
-			</a>
-		</li>
-	</ul>
-</nav>
+			<?php foreach ($pagesVisible as $page): ?>
+				<?php if ($page == $this->context->transport->page): ?>
+					<li class="active">
+				<?php else: ?>
+					<li>
+				<?php endif ?>
+					<a href="<?php echo pageUrl($page) ?>">
+						<?php echo $page ?>
+					</a>
+				</li>
+			<?php endforeach ?>
+
+			<?php if ($this->context->transport->page < $this->context->transport->pageCount): ?>
+				<li class="next">
+			<?php else: ?>
+				<li class="next inactive">
+			<?php endif ?>
+				<a href="<?php echo pageUrl($this->context->transport->page + 1) ?>">
+					&raquo;
+				</a>
+			</li>
+		</ul>
+	</nav>
+<?php endif ?>