WordPress每天自动发布每天60秒读懂世界教程
关注头条号【天域云网络】浏览更多内容前言
通过本篇教程可以在自己的wordperss中增加每日定时发布《每天60秒读懂世界》中的文章,可以有效的提高站点的SEO,并且自动创建到每天60秒读懂世界的分类中。
开始教程
第一步:新在本文最底部查看原文下载我制作好的60s。php文件。或者新建一个60s。php文件,将60s。php文件上传到您需要放置的目录上。复制粘贴以下代码到60s。php文件中保存。lt;?phpdatefilegetcontents(https:www。zhihu。comapiv4columnsc1261258401923026944items);datejsondecode(date);contentdatedata〔0〕content;patternimg。?srcimg03。bs178。comcayq5c7276d5993418c4。jpg;pregmatch(pattern,content,matches);srcpathmatches〔1〕;srcimagecreatefromstring(filegetcontents(srcpath));infogetimagesize(srcpath);裁剪开区域左上角的点的坐标x0;y0;裁剪区域的宽和高width720;height350;最终保存成图片的宽和高,和源要等比例,否则会变形finalwidth720;finalheightround(finalwidthheightwidth);将裁剪区域复制到新图片上,并根据源和目标的宽高进行缩放或者拉升newimageimagecreatetruecolor(finalwidth,finalheight);imagecopyresampled(newimage,src,0,0,x,y,finalwidth,finalheight,width,height);extpathinfo(srcpath,PATHINFOEXTENSION);randnamedate(Ymd)。。。ext;创建文件夹保存图片if(!fileexists(60s)){mkdir(60s,0777,true);}imagejpeg(newimage,60s。randname);imagedestroy(src);imagedestroy(newimage);contentstriptags(content,p);contentimgclasssizefullwpimage156aligncentersrca2020imgdataimg。jpgdatasrcimg03。bs178。comcayq27a790fed030cf30。jpgwidth720height350。content;requireDIR。wpconfig。php;globalwpdb;datedefaulttimezoneset(PRC);posttagarrarray();先检查文章分类是否存在termtaxonomyidwpdbgetrow(SELECTtt。termtaxonomyidfromwpdbtermstjoinwpdbtermtaxonomyttont。termidtt。termidwheret。name每天60秒读懂世界andtt。taxonomycategory)termtaxonomyid;if(!termtaxonomyid){wpdbquery(insertintowpdbterms(name,slug,termgroup)VALUES(每天60秒读懂世界,60秒,0));categoryidwpdbinsertid;wpdbquery(insertintowpdbtermtaxonomy(termid,taxonomy,description,parent,count)VALUES(categoryid,category,,0,1));termtaxonomyidwpdbinsertid;}posttagarr〔〕termtaxonomyid;htmlcontent;标题titledatedata〔0〕title;标题存在则不插入postswpdbgetrow(SELECTidfromwpdbpostswhereposttitletitle);if(!posts){nowcurrenttime(mysql);nowgmtcurrenttime(mysql,1);wpdbinsert(wpdbposts,array(postauthor1,postdatenow,postdategmtnowgmt,postcontenthtml,posttitletitle,postexcerpt,poststatuspublish,commentstatusopen,pingstatusopen,postpassword,postnametitle,toping,pinged,postmodifiednow,postmodifiedgmtnowgmt,postcontentfiltered,postparent0,guid,文章链接插入后修改menuorder0,posttypepost,postmimetype,commentcount0,));insertidwpdbinsertid;postguidgetoption(home)。?p。insertid;wpdbquery(UPDATEwpdbpostsSETguidpostguidwhereidinsertid);插入文章和分类、标签、专题的关系sqlINSERTINTOwpdbtermrelationships(objectid,termtaxonomyid,termorder)VALUES;foreach(posttagarraskeyvalue){sql。(insertid,value,0),;}wpdbquery(rtrim(sql,,));设置文章阅读次数,2050之间的随机数viewsnummtrand(20,50);wpdbquery(INSERTINTOwpdbpostmeta(postid,metakey,metavalue)VALUES(insertid,views,viewsnum));插入文章点赞次数,515之间的随机数likenummtrand(5,15);wpdbquery(INSERTINTOwpdbpostmeta(postid,metakey,metavalue)VALUES(insertid,like,likenum));}打开60s。php修改第32行的地址修改为文件放置的目录地址即可。
第二步:宝塔设置定时任务
设置任务类型:访问URL你的地址60s。php,设置执行周期每天凌晨即可。
查看原文:WordPress每天自动发布《每天60秒读懂世界》新闻【WP教程】天域博客