搜索
系统检测到您的用户名不符合规范:

sitemap 查询多个表的时候该怎么办

浏览:296 发布日期:2019年09月16日 分类:求助交流 关键字: sitemap
class SitemapAction extends Action {

//生成sitemap
public function create() {
$page_size = 10000; //每页条数
$bp_db = M('BaobeiProducts');
//1w个地址生成一个子地图,判断需要生成几个?
$count = $bp_db->where('status = 1')->count();
$page_count = ceil($count/$page_size); //分几个文件

$this->create_index($page_count); //生成主sitemap
$this->create_child($page_count,$page_size); //生成子sitemap


$this->success('地图生成成功');

}

//生成主sitemap
protected function create_index($page_count) {

$content = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<sitemapindex xmlns=\" http://www.sitemaps.org/schemas/sitemap/0.9\">\r\n";
for($i=1;$i<=$page_count;$i++) {

$content .="<sitemap>\r\n<loc> http://HOST/sitemap/sitemap".$i.".xml</loc>\r\n<lastmod>".date('Y-m-d')."</lastmod>\r\n</sitemap>";
}
$content .= "</sitemapindex>";

$file = fopen("sitemap.xml","w");
fwrite($file,$content);
fclose($file);


}

//生成子sitemap
protected function create_child($page_count,$page_size) {

for($i=0;$i<$page_count;$i++) {

$list = M('BaobeiProducts')->field('id,m_time')->order('id asc')->limit($i*$page_size.','.$page_size)->select();

$sitemap = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\r\n";
foreach($list as $k=>$v){
$sitemap .= "<url>\r\n"."<loc>http://HOST/baobei/".$v['id']."</loc>\r\n"."<priority>0.6</priority>\r\n<lastmod>".date('Y-m-d',$v['m_time'])."</lastmod>\r\n<changefreq>weekly</changefreq>\r\n</url>\r\n";

}

$sitemap .= '</urlset>';

$file = fopen("sitemap/sitemap".($i+1).".xml","w");
fwrite($file,$sitemap);
fclose($file);
}
}

}
最佳答案
评论() 相关
后面还有条评论,
评论支持使用[code][/code]标签添加代码
您需要登录后才可以评论 登录 | 立即注册
收藏
粽叶飘5y
积分:400 等级:LV2
热点推荐
(追記) (追記ここまで)
最新更新

我们

合作

网站

信息

ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。

AltStyle によって変換されたページ (->オリジナル) /