我想创建一个站点地图,但我对Sitemaps的使用知之甚少.我用Cake
PHP.谷歌和指南上有很多软件,但我仍然想要问一下,为CakePHP创建站点地图的简单方法.
我在服务器上传了网站,它不依赖于localhost.
这是一个快速的例子供您玩耍并根据您的需求进行调整:
在你的控制器中:
public $components = array('RequestHandler'); public function sitemap() { Configure::write('debug',0); $articles = $this->Article->getSitemapinformation(); $this->set(compact('articles')); $this->RequestHandler->respondAs('xml'); }
你的“文章”模型:
public function getSitemapinformation() { return $this->find('all',array(/* your query here */)); }
视图:
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <?PHP foreach ($articles as $article): ?> <url> <loc><?PHP echo Router::url(/* generate the URLs here */); ?></loc> <lastmod><?PHP echo $time->toAtom(/* last update time here */); ?></lastmod> <changefreq>weekly</changefreq> </url> <?PHP endforeach; ?> </urlset>
原文地址:https://www.jb51.cc/php/135793.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。