说明
handsome
主题一言功能使用的是hitokoto.cn的一言API
,本次实践将其替换为自己的一言API
。
一言API
的搭建方法可以看这里:
本修改对应handsome版本号为
6.0.0
实践过程
修改handsome
主题的index.php
文件,路径为Typecho根目录/usr/themes/handsome/index.php
;
原始代码为:
<!--/公告位置-->
<?php endif; ?>
<header class="bg-light lter b-b wrapper-md">
<h1 class="m-n font-thin h3 text-black l-h"><?php $this->options->title(); ?></h1>
<small class="text-muted letterspacing indexWords"><?php
if (@!in_array('hitokoto',$this->options->featuresetup)) {
$this->options->Indexwords();
}else{
echo '加载中……';
echo '<script>
$.ajax({
type: \'Get\',
url: \'https://v1.hitokoto.cn/\',
success: function(data) {
var hitokoto = data.hitokoto;
$(\'.indexWords\').text(hitokoto);
}
});
</script>';
}
?></small>
</header>
<div class="wrapper-md" id="post-panel">
<!--首页输出文章-->
方法一:使用JS调用
<!--/公告位置-->
<?php endif; ?>
<header class="bg-light lter b-b wrapper-md">
<h1 class="m-n font-thin h3 text-black l-h"><?php $this->options->title(); ?></h1>
<small class="text-muted letterspacing indexWords"><?php
if (@!in_array('hitokoto',$this->options->featuresetup)) {
$this->options->Indexwords();
}else{
echo '加载中……';
echo '<script>
$.post("https://your-domain/hitokoto/", function(hitokoto) {
$(".indexWords").html(hitokoto);
});
</script>';
}
?></small>
</header>
<div class="wrapper-md" id="post-panel">
<!--首页输出文章-->
方法二:使用PHP调用
<!--/公告位置-->
<?php endif; ?>
<header class="bg-light lter b-b wrapper-md">
<h1 class="m-n font-thin h3 text-black l-h"><?php $this->options->title(); ?></h1>
<?php $hitokoto = file_get_contents('https://your-domain/hitokoto/'); ?>
<?php echo $hitokoto; ?>
</header>
<div class="wrapper-md" id="post-panel">
<!--首页输出文章-->
注意
需要把代码中的https://your-domain
地址替换为你自己的一言 API
地址。
文章作者:Vann
本文链接:https://blog.imvann.com/4.html
转载请注明本文链接
大佬能不能写个最新版的修改教程