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

# 前言
[![](http://rxnb37trq.hn-bkt.clouddn.com/072b1689168925.jpg)](http://rxnb37trq.hn-bkt.clouddn.com/072b1689168925.jpg)

最近看各个站点都有的每日六十秒读世界的文章或者页面,大多数实现方式大致两种:一种是emlog中相关的插件或者采集,此方法虽然配置简单、方便,但是这个采集文章内容具有很强的时效性,需要每日定时访问触发采集才能发布文章;一种是直接引用别人的六十秒读世界的api,此方法最大的优点是不用设置采集和发布大量文章,但是形式是仅仅的一张图片,这就过于简单的了,那有还有比前两种更好点又不太简单的实现方式?,答案有是有的?,其实就是将接口写在主题中
# 实现方式

1.在模板主题的module.php文件添加以下函数
```php
data[0]->content;
$content = preg_replace('/([\s\S]*?<\/a>)/','',$content);
$pattern ='';
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,'

');
$content = 'Emlog模板添加每日60秒读世界独立页面'.$content;
return $content;
};
?>
```
2.在自己使用的模板创建独立页面,以60s.php为例,根据各自的主题在文章内容部分添加调用显示
```php

```

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情

    暂无评论内容