[SOLVED] Pagination
-
- Ssr. Bludit
- Posts: 25
- Joined: Sat Dec 15, 2018 11:37 pm
- Has thanked: 4 times
- Been thanked: 2 times
On my blog, there are the 'default' bludit pagination buttons Home, Back and Previous
Is there a simple way / code snippet example adding also page-numbers between this pagination-buttons, similar like this:
Is there a simple way / code snippet example adding also page-numbers between this pagination-buttons, similar like this:
Last edited by ctuxboy on Thu Jan 05, 2023 8:22 pm, edited 1 time in total.
-
- Ssr. Bludit
- Posts: 25
- Joined: Sat Dec 15, 2018 11:37 pm
- Has thanked: 4 times
- Been thanked: 2 times
Yes, some themes have nice options where can learn a lot. i love it
In the meanwhile ported a pagination-function from a theme; do a little customation (css) and it works now
Screenshot: Above the default pagination-function, below the better pagination-function
You can see the result on the bottom of my website: https://gewoonsimpel.be/
- Misteric
- Ssr. Bludit
- Posts: 16
- Joined: Mon Aug 08, 2022 2:55 pm
- Has thanked: 3 times
- Been thanked: 6 times
A pagination script with numbers, first and last button:
Code: Select all
<?php
if(!isset($_GET['page'])){
$getPage = 1;
} else {
$getPage = $_GET['page'];
}
?>
<ul class="list-group flex-md-row">
<?php if($getPage != 1) { ?>
<li class="list-group-item">
<a class="btn btn-dark" href="<?php echo Theme::siteUrl(); ?>?page=1">First</a>
</li>
<?php } ?>
<?php if ($getPage >= 3) { ?>
<li class="list-group-item">
<a class="btn btn-dark" href="<?php echo Theme::siteUrl(); ?>?page=<?php echo $getPage - 2; ?>"><?php echo $getPage - 2; ?></a>
</li>
<?php } ?>
<?php if ($getPage >= 2) { ?>
<li class="list-group-item">
<a class="btn btn-dark" href="<?php echo Theme::siteUrl(); ?>?page=<?php echo $getPage - 1; ?>"><?php echo $getPage - 1; ?></a>
</li>
<?php } ?>
<?php if ($getPage) { ?>
<li class="list-group-item">
<a class="btn btn-warning" href="<?php echo Theme::siteUrl().'?page='.$getPage; ?>"><?php echo $getPage; ?></a>
</li>
<?php } ?>
<?php if (Paginator::numberOfPages()-1 >= $getPage) { ?>
<li class="list-group-item">
<a class="btn btn-dark" href="<?php echo Theme::siteUrl().'?page='.$getPage + 1; ?>"><?php echo $getPage + 1; ?></a>
</li>
<?php } ?>
<?php if (Paginator::numberOfPages()-2 >= $getPage) { ?>
<li class="list-group-item">
<a class="btn btn-dark" href="<?php echo Theme::siteUrl().'?page='.$getPage + 2; ?>"><?php echo $getPage + 2; ?></a>
</li>
<?php } ?>
<?php if(Paginator::numberOfPages() != $getPage) { ?>
<li class="list-group-item">
<a class="btn btn-dark" href="<?php echo Theme::siteUrl().'?page='.Paginator::numberOfPages(); ?>">Last</a>
</li>;
<?php } ?>
-
- Jr. Bludit
- Posts: 6
- Joined: Fri Sep 15, 2023 1:24 pm
- Has thanked: 2 times
- Been thanked: 2 times
I modified some parts of the above code to make it work in blogx theme.
below code works in category and tag pages too. And also adds some dots (...) after first and before the last page.
and this is CSS I used with the above code + in blogx theme:
below code works in category and tag pages too. And also adds some dots (...) after first and before the last page.
Code: Select all
<?php
if(!isset($_GET['page'])){
$getPage = 1;
} else {
$getPage = $_GET['page'];
}
?>
<ul class="list-group flex-md-row">
<?php if ($getPage >= 4) { ?>
<li class="list-group-item">
<a class="btn" href="<?php echo parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); ?>">Firsta>
</li>
<li>... </li>
<?php } ?>
<?php if ($getPage >= 3) { ?>
<li class="list-group-item">
<a class="btn" href="<?php echo parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); ?>
?page=<?php echo $getPage - 2; ?>"><?php echo $getPage - 2; ?></a>
</li>
<?php } ?>
<?php if ($getPage >= 2) { ?>
<li class="list-group-item">
<a class="btn" href="<?php echo parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); ?>
?page=<?php echo $getPage - 1; ?>"><?php echo $getPage - 1; ?></a>
</li>
<?php } ?>
<?php if ($getPage) { ?>
<li class="list-group-item">
<a class="btn btn-selected" href="<?php echo parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); ?>
?page=<?php echo $getPage; ?>"><?php echo $getPage; ?></a>
</li>
<?php } ?>
<?php if (Paginator::numberOfPages()-1 >= $getPage) { ?>
<li class="list-group-item">
<a class="btn" href="<?php echo parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); ?>
?page=<?php echo $getPage + 1; ?>"><?php echo $getPage + 1; ?></a>
</li>
<?php } ?>
<?php if (Paginator::numberOfPages()-2 >= $getPage) { ?>
<li class="list-group-item">
<a class="btn" href="<?php echo parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); ?>?page=<?php echo $getPage + 2; ?>"><?php echo $getPage + 2; ?></a>
</li>
<?php } ?>
<?php if (Paginator::numberOfPages()-3 >= $getPage) { ?>
<li>... </li>
<li class="list-group-item">
<a class="btn" href="<?php echo parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH).'?page='.Paginator::numberOfPages(); ?>">Last</a>
</li>
<?php } ?>
Code: Select all
.list-group-item {
position: relative;
display: inline-block;
padding: 0;
background-color: #fff;
border: none;
margin: 0 4px 10px 0px;
}
.btn {
padding: 2px 10px 0 10px;
border: 1px solid rgba(0,0,0,.125);
border-radius: 3px;
font-size: 17px;
}
.btn-selected,
.btn:hover {
color: #fff;
background-color: #036BAA;
font-weight:600;
}