How to Make the Content ID on Typecho continuous

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

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?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

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/** 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

PHP
1
2
3
4
5
<?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

https://blog.tsinbei.com/en/archives/58/

Author
Hsukqi Lee
Posted on

2022-01-18

Edited on

2022-07-28

Licensed under

CC BY-NC-ND 4.0

# Typecho  SQL

Comments

Name
Mail
Site
None yet