zblog php 正确编写sitemapindex的代码,

当你的sitemap 文件很多时候,不能一个一个提交,可以使用sitemapindex 格式统一提交管理,非常方便,百度 谷歌 主流搜索也支持。




<?php
header("Content-type: text/xml");
header('HTTP/1.1 200 OK');
require 'zb_system/function/c_system_base.php';

$zbp->host = 'http://美食汇';

$str = '<?xml version="1.0" encoding="UTF-8"?>';
$str .= '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';

$str .= '<sitemap>';
$str .= '<loc>' . $zbp->host . 'sitemap.xml</loc>';
$str .= '<lastmod>' . date("Y-m-d") . '</lastmod>';
$str .= '</sitemap>';


//$db = $zbp->db->sql->get();
//$sql = $db->select($zbp->table['Post'])->where(array('=', 'log_Status', '0'))->sql;
//$array = $zbp->GetListType('Post', $sql);


$num = GetValueInArrayByCurrent($zbp->db->Query('SELECT COUNT(*) AS num FROM ' . $zbp->table['Post'] . ' WHERE log_Status=\'0\''), 'num') / 1000;

for ($i = 0; $i < $num; $i++) {
    $str .= '<sitemap>';
    $str .= '<loc>' . $zbp->host . 'sitemap_' . $i . '.xml</loc>';
    $str .= '<lastmod>' . date("Y-m-d") . '</lastmod>';
    $str .= '</sitemap>';
}

//$sql= $zbp->db->sql->Select($zbp->table['Post'],'count(*)',array(array('=', 'log_Status', '0')),null,null,null);
//$array=$zbp->GetListCustom($koilee_Table,$koilee_DataInfo,$sql);

//foreach ($array as $post) {
//    $str .= '<url>';
//    $str .= '<loc>' . $post->Url . '</loc>';
//    $str .= '<mobile:mobile type="pc,mobile"/>';
//    $str .= '<lastmod>' . $post->Time('Y-m-d') . '</lastmod>';
//    $str .= '<changefreq>daily</changefreq>';
//    $str .= '<priority>0.8</priority>';
//    $str .= '</url>';
//}
//
//$allCats = $zbp->GetCategoryList();
//foreach ($allCats as $cat) {
//    $str .= '<url>';
//    $str .= '<loc>' . $cat->Url . '</loc>';
//    $str .= '<mobile:mobile type="pc,mobile"/>';
//    $str .= '<lastmod>' . date('Y-m-d', time()) . '</lastmod>';
//    $str .= '<changefreq>daily</changefreq>';
//    $str .= '<priority>0.6</priority>';
//    $str .= '</url>';
//}
//
//$allTags = $zbp->GetTagList();
//foreach ($allTags as $tat) {
//    $str .= '<url>';
//    $str .= '<loc>' . $tat->Url . '</loc>';
//    $str .= '<mobile:mobile type="pc,mobile"/>';
//    $str .= '<lastmod>' . date('Y-m-d', time()) . '</lastmod>';
//    $str .= '<changefreq>monthly</changefreq>';
//    $str .= '<priority>0.3</priority>';
//    $str .= '</url>';
//}

$str .= '</sitemapindex>';

echo $str;
unset($str);
?>

 

 

效果如

zblog php 正确编写sitemapindex的代码,