Sitemap 可方便网站管理员通知搜索引擎他们网站上有哪些可供抓取的网页。最简单的 Sitemap 形式,就是XML 文件,在其中列出网站中的网址以及关于每个网址的其他元数据(上次更新的时间、更改的频率以及相对于网站上其他网址的重要程度为何等),以便搜索引擎可以更加智能地抓取网站。
目前有两种格式
<urlset xmlns=“网页列表地址”> <url> <loc>网址</loc> <lastmod>2005-06-03T04:20-08:00</lastmod> <changefreq>always</changefreq> <priority>1.0</priority> </url> <url> <loc>网址</loc> <lastmod>2005-06-02T20:20:36Z</lastmod> <changefreq>daily</changefreq> <priority>0.8</priority> </url> </urlset>
<?xml version="1.0" encoding="UTF-8"?> <urlset> <url> <loc>网页地址</loc> <lastmod>2010-01-01</lastmod> <changefreq>daily</changefreq> <priority>1.0</priority> </url> </urlset>
新建一个文本文件把代码粘贴进去,然后另存为utf-8格式的文件,文件名为sitemap.xml,然后把这个文件上传到自己网站的对应的根目录下面;
某东www.jd.com/sitemap.xml
如果是一般商城的,可以从date.php(定时更新页面)入手
shopnc
/**
     * 生成sitemap.xml文件
     * @return [type] [description]
     */
    function _create_sitemap(){
        //首页
        $index = "<url>";
        $index .= "<loc>".SHOP_SITE_URL."</loc>"; 
        $index .= "<lastmod>". date("Y-m-d")."</lastmod>";//最后更新日期
        $index .= "<changefreq>always</changefreq>";//更新频率 可选"always", "hourly", "daily", "weekly", "monthly", "yearly"
        $index .= "<priority>1.0</priority>"; //优先权 此值定于0.0 - 1.0之间
        $index .= "</url>";
        //登录页面
        $index .= "<url>";
        $index .= "<loc>".SHOP_SITE_URL.DS."index.php?act=login</loc>"; 
        $index .= "<lastmod>". date("Y-m-d")."</lastmod>";//最后更新日期
        $index .= "<changefreq>weekly</changefreq>";//更新频率 可选"always", "hourly", "daily", "weekly", "monthly", "yearly"
        $index .= "<priority>0.9</priority>"; //优先权 此值定于0.0 - 1.0之间
        $index .= "</url>";
        //注册页面
        $index .= "<url>";
        $index .= "<loc>".SHOP_SITE_URL.DS."index.php?act=login&op=register</loc>"; 
        $index .= "<lastmod>". date("Y-m-d")."</lastmod>";//最后更新日期
        $index .= "<changefreq>weekly</changefreq>";//更新频率 可选"always", "hourly", "daily", "weekly", "monthly", "yearly"
        $index .= "<priority>0.9</priority>"; //优先权 此值定于0.0 - 1.0之间
        $index .= "</url>";
        //app下载页面
        $index .= "<url>";
        $index .= "<loc>".BASE_SITE_URL.DS."app/index.html</loc>"; 
        $index .= "<lastmod>". date("Y-m-d")."</lastmod>";//最后更新日期
        $index .= "<changefreq>weekly</changefreq>";//更新频率 可选"always", "hourly", "daily", "weekly", "monthly", "yearly"
        $index .= "<priority>0.9</priority>"; //优先权 此值定于0.0 - 1.0之间
        $index .= "</url>";
        //商品分类
        $goods_class = Model("goods_class")->getGoodsClassList(array("gc_show"=>1), "gc_id, gc_name");
        $gc = "";
        foreach($goods_class as $val){
            $gc .= "<url>";
            $gc .= "<loc>".urlShop("search","index",array("cate_id"=>$val["gc_id"]))."</loc>"; 
            $gc .= "<lastmod>". date("Y-m-d")."</lastmod>";//最后更新日期
            $gc .= "<changefreq>weekly</changefreq>";//更新频率 可选"always", "hourly", "daily", "weekly", "monthly", "yearly"
            $gc .= "<priority>0.9</priority>"; //优先权 此值定于0.0 - 1.0之间
            $gc .= "</url>";
        }   
        //设计师
        $designer_list = Model("designer")->getDesignerList(array("designer_status"=>1), "designer_id, designer_name");
        $dl = "";
        foreach($designer_list as $val){
            $dl .= "<url>";
            $dl .= "<loc>".urlDesigner("designer","index",array("d_id"=>$val["designer_id"]))."</loc>"; 
            $dl .= "<lastmod>". date("Y-m-d")."</lastmod>";//最后更新日期
            $dl .= "<changefreq>weekly</changefreq>";//更新频率 可选"always", "hourly", "daily", "weekly", "monthly", "yearly"
            $dl .= "<priority>0.9</priority>"; //优先权 此值定于0.0 - 1.0之间
            $dl .= "</url>";
        }
        //设计师资讯
        $dnews_list = Model("dnews")->getArticleList(array(), 0);
        $dn = "";
        foreach ($dnews_list as $val) {
            $dn .= "<url>";
            $dn .= "<loc>".urlDnews("dnews","detail",array("dnews_id"=>$val["dnews_id"]))."</loc>"; 
            $dn .= "<lastmod>". date("Y-m-d")."</lastmod>";//最后更新日期
            $dn .= "<changefreq>weekly</changefreq>";//更新频率 可选"always", "hourly", "daily", "weekly", "monthly", "yearly"
            $dn .= "<priority>0.9</priority>"; //优先权 此值定于0.0 - 1.0之间
            $dn .= "</url>";
        }
            
        //商品列表
        $goods_list = Model("goods")->getGoodsOnlineList(array(), "goods_id, goods_name", 0, "goods_id desc", 5000);
        $gl = "";
        foreach($goods_list as $val){
            $gl .= "<url>";
            $gl .= "<loc>".urlShop("goods","index",array("goods_id"=>$val["goods_id"]))."</loc>"; 
            $gl .= "<lastmod>". date("Y-m-d")."</lastmod>";//最后更新日期
            $gl .= "<changefreq>daily</changefreq>";//更新频率 可选"always", "hourly", "daily", "weekly", "monthly", "yearly"
            $gl .= "<priority>0.8</priority>"; //优先权 此值定于0.0 - 1.0之间
            $gl .= "</url>";
        }
        $str = ‘<?xml version="1.0" encoding="utf-8"?>‘."<urlset>".$index.$gc.$dl.$dn.$gl."</urlset>";
        @file_put_contents(BASE_ROOT_PATH.DS."sitemap.xml", $str);
}
sitemap.xml 静态和动态生成页面 shopnc二次开发 动态生成sitemap.xml
原文:http://www.cnblogs.com/lemonphp/p/5492145.html