您的位置 首页 php

php自动生成sitemap

1.jpg

网站的sitemap是爬虫抓取的主要地方,提交了sitemap的url,爬虫会优先抓取。

所以我们平时要有定期更新sitemap的习惯,生成sitemap的方法有很多,第三方工具抓取生成,自己生成。这里我推荐自己生成sitemap。因为这样消耗系统资源最少。

代码如下:

include_once Root_Path . "/vendor/autoload.php";use Medoo\Medoo;$db = new Medoo(['database_type' => 'mysql','database_name' => 'menghuiguli','server' => 'localhost','username' => 'root','password' => 'root',]);$str = "<ul>";$articles = $db->select('article',"*");foreach ($articles as $k => $v) {$str .= '<li><div class="T1"><a href="https://www.80shihua.com/archives/'.$v['id'].'" title="'.$v['name'].'">'.$v['name'].'</a></div><div class="T2">2019-02-02T10:16:23+08:00</div><div class="T3">monthly</div><div class="T4">0.5</div></li>';}$str .= '</ul>';file_put_contents('/sitemap.html', $str);

其中数据库我使用了最小巧的medooORM模型,非常方便。

我们只要查出相关文章,然后对应循环生成sitemap即可。

更多PHP相关知识,请访问PHP中文网!

以上就是php自动生成sitemap的详细内容,更多请关注求知技术网其它相关文章!

文章来源:智云一二三科技

文章标题:php自动生成sitemap

文章地址:https://www.zhihuclub.com/3080.shtml

关于作者: 智云科技

热门文章

网站地图