sitemap站点地图(3)

发布时间:2015-12-14 13:33:38编辑:丝画阁阅读(459)

        $allsitemap = array();//索引XML数组

       

        $httpd = C('DOMAIN');//网站地址
        $number = 10000;       //每个XML文件存放多少条URL


        //查询表中的文章,根据文章信息生成文章的URL.然后生成站点地图

        $map = array();
        $map['status'] = 1;
        $map["ischeck"] = 1;
        $lists = M("baike")->where($map)->order($order)->field("id,domainid")->select();
        if($lists){
            $b=array();
            foreach( $lists as $k=>$v ){
            $b[]= $httpd.U(MODULE_NAME.'/Baike/detail',array('id'=>$v['id']));
            }
            $this->mkdirp(SITE_PATH."sitemap");

            $chunk = array_chunk($b, $number, TRUE);
            foreach($chunk as $qkey=>$qvaluep){
                $xml = "";
                $xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
                $xml .= "<urlset>\n";
                foreach ($qvaluep as $data) {
                    $xml .= $this->create_item($data, date('Y-m-d'), 'daily', 0.3);
                }
                $xml .= "</urlset>\n";
                //XML保存地址
                $xmldir = SITE_PATH."sitemap/baike".$qkey.".xml";
                //XML文件写入
                file_put_contents($xmldir,$xml);
                //统计XML信息
                $allsitemap[] = array($httpd."/sitemap/baike".$qkey.".xml",time());
            }

        }


        $xml = "";
        $xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
        $xml .= "<sitemapindex>\n";
        foreach ($allsitemap as $data) {
            $xml .= $this->create_siteitem($data[0], date('Y-m-d',$data[1]));
        }
        $xml .= "</sitemapindex>\n";
        //XML保存地址
        $xmldir = SITE_PATH."sitemap.xml";
        //XML文件写入
        file_put_contents($xmldir,$xml);

关键字