Last active
August 26, 2023 07:52
-
-
Save james2doyle/414bbfe37a51f3907e90 to your computer and use it in GitHub Desktop.
Simple pagination element with dot separation when large counts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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
As @pimpattcha pointed out, it works well without the first if statement.
Thanks and you save the day