Skip to content

Instantly share code, notes, and snippets.

@parag60288
Forked from james2doyle/pagination.php
Created July 16, 2023 19:10
Show Gist options
  • Save parag60288/999ad56d305362899d12485b979ddf49 to your computer and use it in GitHub Desktop.
Save parag60288/999ad56d305362899d12485b979ddf49 to your computer and use it in GitHub Desktop.
Simple pagination element with dot separation when large counts
<div class="pagination size1of1 unit">
<?php if($paged == 1): ?>
<span class="current"><?php echo $paged ?></span>
<?php else: ?>
<a class="prev" href="?page=<?php echo ($current_page - 1) ?>">Prev</a>
<?php if ($current_page > 2): ?>
<a href="?page=1">1</a>
<?php endif ?>
<?php if ($current_page > 3): ?>
<span class="dots">...</span>
<?php endif ?>
<?php endif ?>
<?php if($current_page - 1 > 0): ?>
<a href="?page=<?php echo $current_page - 1 ?>"><?php echo $current_page - 1 ?></a>
<?php endif ?>
<span class="current"><?php echo $current_page ?></span>
<?php if ($current_page + 1 < $max_num_pages): ?>
<a href="?page=<?php echo $current_page + 1 ?>"><?php echo $current_page + 1 ?></a>
<?php endif ?>
<?php if($current_page < $max_num_pages): ?>
<?php if ($current_page < $max_num_pages - 2): ?>
<span class="dots">...</span>
<?php endif ?>
<a href="?page=<?php echo $max_num_pages ?>"><?php echo $max_num_pages ?></a>
<a class="next" href="?page=<?php echo ($current_page + 1) ?>">Next</a>
<?php endif ?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment