Typecho 主题自定义分页按钮样式的解决方案
最近在整改站点的主题,为了让整站更加美观,刻意研究了一波分页按钮的美化操作。
由于 typecho 官方或其他第三方提供的方案感觉有点麻烦,我就自己研究了一个好像也很麻烦的方案,不过可以参考参考。
首页的自定义分页:
<?php
$totalPage = ceil($this->getTotal() / $this->parameter->pageSize);
if($this->_currentPage <= 1) {
$this->_currentPage = 1;
}
if($this->_currentPage-1 <= 0) {
$currentPage = 1;
} else {
$currentPage = $this->_currentPage-1;
}
if($this->_currentPage+1 >= $totalPage) {
$nextPage = $totalPage;
} else {
$nextPage = $this->_currentPage+1;
}
?>
<div class="btn-toolbar justify-content-center mb-3" role="toolbar">
<div class="btn-group btn-group-sm me-2 mb-2" role="group">
<button type="button" class="btn btn-light fw-normal" onclick="location.href='/page/1/'">首页</button>
<button type="button" class="btn btn-light fw-normal" onclick="location.href='/page/<?php echo $currentPage ?>/'">上一页</button>
<button type="button" class="btn btn-light fw-normal" onclick="location.href='/page/<?php echo $nextPage ?>/'">下一页</button>
<button type="button" class="btn btn-light fw-normal" onclick="location.href='/page/<?php echo $totalPage ?>/'">末页</button>
</div>
<div class="btn-group btn-group-sm mb-2" role="group">
<button type="button" class="btn btn-light fw-normal">当前第<?php echo $this->_currentPage ?>页 / 共<?php echo $totalPage ?>页</button>
</div>
</div>评论区的自定义分页:
<?php
$perurl = $comments->parameter->parentContent['permalink'];
$total = $comments->parameter->parentContent['commentsNum'];
$pageSize = $comments->options->row['commentsPageSize'];
$current = $comments->parameter->commentPage;
$totalPage = ceil($total / $pageSize);
if($current <= 1) {
$current = 1;
}
if($current-1 <= 0) {
$currentPage = 1;
} else {
$currentPage = $current-1;
}
if($current+1 >= $totalPage) {
$nextPage = $totalPage;
} else {
$nextPage = $current+1;
}
?>
<div class="btn-toolbar justify-content-center mb-3" role="toolbar">
<div class="btn-group btn-group-sm me-2 mb-2" role="group">
<button type="button" class="btn btn-light fw-normal" onclick="location.href='<?php echo $perurl."/comment-page-1"?>'">首页</button>
<button type="button" class="btn btn-light fw-normal" onclick="location.href='<?php echo $perurl."/comment-page-".$currentPage ?>/'">上一页</button>
<button type="button" class="btn btn-light fw-normal" onclick="location.href='<?php echo $perurl."/comment-page-".$nextPage ?>/'">下一页</button>
<button type="button" class="btn btn-light fw-normal" onclick="location.href='<?php echo $perurl."/comment-page-".$totalPage ?>/'">末页</button>
</div>
<div class="btn-group btn-group-sm mb-2" role="group">
<button type="button" class="btn btn-light fw-normal">当前第<?php echo $current ?>页 / 共<?php echo $totalPage ?>页</button>
</div>
</div>