Add Page Numbers in Typecho

0, question

When I first started writing articles on my blog, although I might be the only one in the monthly PV (and disappointedcrawlers?), I still registered for Google Search Console for the first time, and then I received emails saying a lot Page duplication, including:

.../page/1/
.../page/2/

For such pagination, the titles are still the same, such as articles under the label "Programming" - Qingbei Blog.

Recently, I checked the information and found out how to change it.

1. Solution

Where the title is output, add the PHP code:

PHP
1
if($this->_currentPage>1) echo 'page '.$this->_currentPage.';

Locations may vary for different topics.

For example, the structure of this theme is relatively complicated, and the code to output the title is in header.php:

PHP
1
printPageTitle();

Most of the source code of this theme was not written by me (modified from the open source warehouse), so it is not easy to locate, and I don’t dare to change the output source code, so I just add the above code directly behind:

PHP
1
2
3
4
<?php
     Icarus_Page::printPageTitle();
     if($this->_currentPage>1) echo ' - page '.$this->_currentPage.'';
?>

This solves the problem simply and crudely.

2, Error troubleshooting

Many themes seem to override $this, maybe advanced PHP? Anyway, I see $widget, $options, etc. in this topic, which are actually $this.

Therefore, if you report an error that $this cannot be found after adding the above code, you can see how the file is quoted.

Thanks

Typecho page title plus page number to get page number
https://www.ityinhu.com/600.html
Author
Hsukqi Lee
Posted on

2022-12-15

Edited on

2022-12-15

Licensed under

CC BY-NC-ND 4.0

Comments

Name
Mail
Site
None yet