Typecho handsome主题一言接口修改,使用自己的一言服务

说明

handsome主题默认使用的是 https://v1.hitokoto.cn 一言接口
博主感觉不是太满意,于是想换成自己的“一言”服务接口
首先需要自己搭建一个“一言”服务接口,搭建方法可以看这里:https://sunpma.com/669.html
搭建好了后就可以按下面的方法替换成自己的接口即可;

修改主题“一言”接口

修改路径位于网站根目录下/usr/themes/handsome/index.php修改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://sunpma.com/other/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://sunpma.com/other/hitokoto/'); ?>
          <?php echo $hitokoto; ?>
        </header>
        <div class="wrapper-md" id="post-panel">
            <!--首页输出文章-->

注意

修改代码中的链接地址需要修改成自己的接口链接;

发表评论 取消回复

9 条评论

  1. 王啊怼

    好哒,感谢大佬~

  2. AomanHao

    很好用 nice

  3. Vann

    可以转到我 `1IP `的博客上吗,这两篇一言的

    1. sunpma
      @Vann

      可以,保留链接即可

      1. Vann
        @sunpma

        感谢~
        另外 想问一下你用的什么主机,我这经常抽风打不开。挂代理没问题。是不是IP被强过

        1. sunpma
          @Vann

          IP没墙过啊,是不是晚上高峰的时候打不开呢?你是什么宽带?

          1. Vann
            @sunpma

            天津联通,全天候抽风。
            应该是我宽带有限制,不知道什么规则。少数几个博客打开有问题,但是你的博客最严重,大部分时间打不开。。。

            1. sunpma
              @Vann

              我经常测试都没问题啊,全国都是秒开,可能个别地区DNS有问题吧

  4. sunpma