Showing an IP location under comments is not just a technical flourish. It adds a bit of accountability: when you cannot keep yourself in check, it helps to pause and think about the consequences. I will admit there is another motive, too—recognizing people from the same hometown. Ha.
The wider context: by the end of December 2021, China had 1.032 billion internet users, an increase of 42.96 million from December 2020, and internet penetration reached 73.0%. The group is mainly teenagers, young people, and middle-aged people.
Step 1: Download the plugin
Download CommentLocation.zip.
Step 2: Install it
Unzip the archive and rename the folder to CommentLocation. Upload it to the site directory under /usr/plugins, then enable the plugin in Typecho's backend under Plugin Management.
Step 3: Deploy it
Place the following code in the appropriate spot in comments.php:
<?php $comments->location(); ?>
The display logic comes down to the following lines. The comments describe what each version is meant to show:
$locationText = empty($location['pro']) ? $location['addr'] : $location['pro'] . $location['city'];
/* This line displays province/city */
$locationText = empty($location['pro']) ? $location['addr'] : $location['city'];
/* This line displays only city */