帝国CMS利用灵动标签制作sitemap.xml网站地图

帝国 CMS 中,利用灵动标签制作sitemap.xml网站地图是一种高效的方法,能够自动生成符合搜索引擎规范的站点地图。以下是具体实现步骤:

方法:创建 sitemap.xml 模板并调用灵动标签

新建 sitemap.xml 模板文件/e/template/目录下新建sitemap文件夹,创建map.xml文件,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <!-- 首页 -->
    <url>
        <loc><?=ReturnSiteIndexUrl()?></loc>
        <lastmod><?=date('Y-m-d')?></lastmod>
        <changefreq>daily</changefreq>
        <priority>1.0</priority>
    </url>
    
    <!-- 栏目页 -->
    [e:loop={"select classid,classname,lastpost from phome_enewsclass where showclass=0 order by classid asc",0,24,0}]
    <url>
        <loc><?=sys_ReturnBqClassUrl($bqr)?></loc>
        <lastmod><?=date('Y-m-d',$bqr['lastpost'])?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.8</priority>
    </url>
    [/e:loop]
    
    <!-- 文章内容页(新闻模型示例) -->
    [e:loop={"select id,newstime from phome_ecms_news where checked=1 order by newstime desc limit 10000",0,24,0}]
    <url>
        <loc><?=sys_ReturnBqTitleLink($bqr)?></loc>
        <lastmod><?=date('Y-m-d',$bqr['newstime'])?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.6</priority>
    </url>
    [/e:loop]
    
    <!-- 其他模型内容页(如产品模型) -->
    [e:loop={"select id,newstime from phome_ecms_product where checked=1 order by newstime desc limit 10000",0,24,0}]
    <url>
        <loc><?=sys_ReturnBqTitleLink($bqr)?></loc>
        <lastmod><?=date('Y-m-d',$bqr['newstime'])?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.6</priority>
    </url>
    [/e:loop]
</urlset>

创建生成 sitemap 的 PHP 文件在网站根目录创建sitemap.php,用于生成并输出 XML:

<?php
require("e/class/connect.php");
require("e/class/db_sql.php");
require("e/class/functions.php");
require("e/class/t_functions.php");
require LoadLang("pub/fun.php");

// 设置输出类型为XML
header("Content-type: text/xml");

// 引入模板
$temppath = ECMS_PATH."e/template/sitemap/map.xml";
require($temppath);
?>

声明:本文来自互联网或用户投稿,该文观点仅代表作者本人,不代表本站立场。文章及其配图仅供学习和交流之用,版权归原作者所有,如有内容侵权或者其他违规问题,请联系本站处理。

相关文章