Emlog添加每日60秒读世界独立页面
网站文章 2026-09-23 09:01:06 3 0

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

实现方式:

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

<?php
//独立页面-每日60秒
function lanli_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.*?>[sS]*?</a>)/','',$content);
$pattern ='<img.*?src="(.*?)" rel="external nofollow" >';
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.'" rel="external nofollow"  />'.$content;
  return $content;
};
?>

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

 <?php echo lanli_sixtys()?>
文章说明
本文标签:
©版权声明
本站提供的一切软件、教程和游戏辅助仅限用于娱乐和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络收集,版权争议与本站无关。如有侵权请邮件与我们联系处理。敬请谅解!6594404@qq.com