Loading... ## 1 效果  ## 2 方法 进入 `<typecho目录>`编辑主题的 `Content.php`文件 ```shell [root@10-23-159-191 typecho]# vim usr/themes/handsome/libs/Content.php ``` 找到 `whenSwitchHeaderImgSrc`函数,注释 `random`变量,替换成随机图源 ```php // 随机图源 $randomImgOrgin = get_headers('https://api.mz-moe.cn/img.php', TRUE)['Location']; $random = $randomImgOrgin; // 随机缩略图路径(注释默认的随机图) // $random = STATIC_PATH . 'img/sj/' . @$randomNum[$index] . '.jpg';//如果有文章置顶,这里可能会导致index not undefined ``` 或者也可以这样: ```php $randomImgOrgin = ""; $OrginKey = ""; switch(rand(1,2)) { case 1: $randomImgOrgin = "https://api.mtyqx.cn/api/random.php?return=json"; $OrginKey = "imgurl"; break; case 2: $randomImgOrgin = "https://api.mtyqx.cn/tapi/random.php?return=json"; $OrginKey = "imgurl"; break; } $responContent = ""; $requestHandle = fopen($randomImgOrgin,"rb"); while (!feof($requestHandle)) { $responContent .= fread($requestHandle, 10000); } fclose($requestHandle); $jsonData = json_decode($responContent, true); $random = $jsonData[$OrginKey]; ``` 需要注意,因为图片都是比较大的,会影响网页的加载速度,这里还将 `handsome`的 `主题增强功能`->`增强功能开关`->`lazyload`开了起来,感觉会好一些  ## 3 随机图源 [随机动漫图片api](https://mz-moe.cn/?p=23) [随机博客api](https://www.cnblogs.com/melodyjerry/p/13322186.html) 最后修改:2021 年 12 月 15 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 0