Typecho默认是如下代码这样调用翻页按钮组件,然后会输出带有a标签的html代码,简单易用,但自定义不够灵活,比如没有办法自定义其class。
<?php $this->pageLink('下一页','next'); ?>
<?php $this->pageLink('上一页'); ?>
所以我反推了下代码,然后实现了自定义,代码教程如下
<?php
//获取翻页链接模板
$pageTemplate=Typecho\Router::url(
$this->parameter->type .
(false === strpos($this->parameter->type, '_page') ? '_page' : null),
$this->pageRow,
$this->options->index
);
?>
<?php if ($this->getTotal() > 0 && $this->currentPage < $this->getTotalPage()):?>
<a href="<?php echo str_replace('', $this->currentPage + 1, $pageTemplate); ?>" class="old">旧的文章</a>
<?php endif;?>
<?php if($this->getTotal() > 0 && $this->currentPage > 1):?>
<a href="<?php echo str_replace('', $this->currentPage - 1, $pageTemplate); ?>" class="new">新的文章</a></div>
<?php endif;?>
原理就是获取翻页链接模板格式为https://xxx.xxx/page/,然后翻页链接将这个标志符换成对应页码即可