0. Description
Typecho's article cid is often discontinuous. Looking at the database, it should be a separate page, and the attachments occupy part of the cid. Therefore, the source code of the database or Typecho needs to be modified to solve this problem.
1, the solution below PHP7
1 | <?php $hostname_blog = "localhost"; $database_blog = "Database Name"; $username_blog = "Database Username"; $password_blog = "Database Password"; $blog = mysql_pconnect($hostname_blog, $username_blog, $password_blog) or trigger_error(mysql_error(),E_USER_ERROR); $no = 1; function change_id($cid) { global $no; // Modify post cid, and modify the correspondence between categories, labels, custom fields, and comments $sql = 'update typecho_contents set cid = ' . $no . ' where cid = ' . $cid; mysql_query($sql); $sql = 'update typecho_relationships set cid = ' . $no . ' where cid = ' . $cid; mysql_query($sql); $sql = 'update typecho_comments set cid = ' . $no . ' where cid = ' . $cid; mysql_query($sql); $no = $no + 1; } mysql_select_db($database_blog, $blog); $query_postRecord = "SELECT cid FROM typecho_contents ORDER BY cid ASC"; $all_postRecord = mysql_query($query_postRecord); $row_postRecord = mysql_fetch_assoc($all_postRecord); do { change_id( $row_postRecord['cid'] ); } while ($row_postRecord = mysql_fetch_assoc($all_postRecord)); // Reset the post id auto-increment starting point mysql_query('alter table typecho_contents AUTO_INCREMENT = ' . $no); echo 'ok'; ?> |
Upload this php file to the root directory of Typecho blog and run it once.
Tip: This method will result in mismatched attachments, please use as appropriate.
2, PHP7 solution
2.1, modify the configuration file
Modify the root directory of the website
config.inc.php
About Acts 61 to 71
1 | /** Define database parameters */ $hostname_blog = "Database connection address"; $database_blog = "Database Name"; $username_blog = "Database Username"; $password_blog = "Database Password"; $db = new Typecho_Db('Pdo_Mysql', 'typecho_'); $db->addServer(array ( 'host' => $hostname_blog, 'user' => $username_blog, 'password' => $password_blog, 'charset' => 'utf8', 'port' => '3306', 'database' => $database_blog, ), Typecho_Db::READ | Typecho_Db::WRITE); Typecho_Db::set($db); |
2.2, increase the sorting program
new
/admin/change-cid.php
/admin/change-mid.php
Fill in:
Comment first then view it after your comment is approved. Join QQ Group to display all hidden texts.
and
Comment first then view it after your comment is approved. Join QQ Group to display all hidden texts.
2.3, modify the file
exist
/admin/manage-posts.php
/admin/manage-categories.php
/admin/manage-tags.php
Add before original content
1 | <?php require "../config.inc.php"; require "change-cid.php"; require "change-mid.php"; ?> |
3. Reference articles
Typecho automatically corrects the discontinuous method of article cid and classification label midhttps://ghostinto.top/archives/22.html
4, matters needing attention
Remember to backup the database before running!
How to Make the Content ID on Typecho continuous
Comments