Emlog模板添加每日60秒读世界独立页面

最近看各个站点都有的每日六十秒读世界的文章或者页面,大多数实现方式大致两种:一种是emlog中相关的插件或者采集,此方法虽然配置简单、方便,但是这个采集文章内容具有很强的时效性,需要每日定时访问触发采集才能发布文章;

一种是直接引用别人的六十秒读世界的api,此方法最大的优点是不用设置采集和发布大量文章,但是形式是仅仅的一张图片,这就过于简单的了,那有还有比前两种更好点又不太简单的实现方式?,答案有是有的,其实就是将接口写在主题中。

实现方式

1.在模板主题的module.php文件添加以下函数

<?php
//独立页面-每日60秒
function luyu_sixtys(){ 
$date = file_get_contents(\"https://www.zhihu.com/api/v4/columns/c_1261258401923026944/items\");
$date = json_decode($date);
$content = $date->data[0]->content;
$content = preg_replace(\'/(<a.*?>[\\s\\S]*?<\\/a>)/\',\'\',$content);
$pattern =\'<img.*?src=\"(.*?)\">\';
preg_match($pattern,$content,$matches);
$src_path = $matches[1];
$src = imagecreatefromstring(file_get_contents($src_path));
$info = getimagesize($src_path);
$x = 0;
$y = 0;
$width = 720;
$height = 350;
$final_width = 720;
$final_height = round($final_width * $height / $width);
$new_image = imagecreatetruecolor($final_width, $final_height);
imagecopyresampled($new_image, $src, 0, 0, $x, $y, $final_width, $final_height, $width, $height);
$ext = pathinfo($src_path, PATHINFO_EXTENSION);
$rand_name = date(\"Ymd\") . \".\" . $ext;
$url= BLOG_URL;
if (!file_exists(\"content/uploadfile/60s\")){
    mkdir (\"content/uploadfile/60s\",0777,true);
}
imagejpeg($new_image,\"content/uploadfile/60s/\".$rand_name);
imagedestroy($src);
imagedestroy($new_image);
$content = strip_tags($content,\'<p>\');
$content = \'<img class=\"\" src=\"\'.$url.\'/content/uploadfile/60s/\'.$rand_name.\'\" />\'.$content;
  return $content;
};
?>

2.在自己使用的模板创建独立页面,以60s.php为例,根据各自的主题在文章内容部分添加调用显示。

<?php echo luyu_sixtys()?>

上一篇 Emlog文章内容自动添加标签链接
下一篇 zblog不能发Emoji表情、颜文字如何解决?

探索站点内容

搜索文章、标签、分类

关注公众号
领美团外卖神券
领美团外卖神券
最新评论
dadaowokou
dadaowokou
10月22日
求更新的
日月先生
日月先生
10月8日
留个言看看
小高网
小高网
10月4日
有更新本帖会重新置顶
7777
7777
10月4日
麻烦置顶
7777
7777
10月3日
那些看剧的app好像没了
hghghg
hghghg
9月24日
强制更新升级,用不了
15579854855
15579854855
9月15日
安装流程都没有,下载也用不了,浪费时间
小高网

小高网管理员

小高网www.xx8g.com

本月创作热力图

少
多