帝国CMS插件开发

帝国CMS插件 · AI · 模板

您当前的位置:首页 > 帝国CMS问题修复

亲测可用帝国CMS完美无报错Sitemap

一、个人实测踩坑总结

最近给帝国CMS站点配置网站地图,踩了一大堆坑,要么报PHP version语法错误,要么XML格式不规范、境外sitemap协议打不开导致页面报错,还有就是相对链接收录异常、内容不全等问题。折腾很久后,我自己整合打磨出一套零报错、稳定适配国内搜索引擎的Sitemap方案。目前已在自己站点实测正常,完美兼容百度、360、搜狗收录,同时支持新闻模型、下载模型,自动抓取首页、所有前台栏目链接,是目前帝国CMS最省心的SEO站点地图方案。

二、我的部署方式(一步步照做即可)

1、进入帝国CMS后台,找到栏目 → 自定义页面 → 增加自定义页面。

2、页面参数我是这样配置的,保证完全无误:

  • 页面模式:直接页面式

  • 页面名称:sitemap.xml

  • 保存文件名:sitemap.xml(直接生成在网站根目录)帝国cms版本不同路径可能有所不同注意查看

  • 所属分类:不隶属于任何类别

3、清空默认内容,直接粘贴我整理好的完整代码。

4、保存后刷新自定义页面,清理一下系统缓存,直接生效。

三、亲测稳定纯净源码(无注释、无BUG)

适配:首页、全站公开栏目、新闻模型、下载模型,支持自动识别域名、链接自动绝对化、XML标准合规。

<?='<?xml version="1.0" encoding="UTF-8"?>'?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <?php global $empire, $dbtbpre, $public_r; // 自动识别HTTPS/HTTP协议 $is_https = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http'; $domain = rtrim($public_r['newsurl'], '/'); if (empty($domain)) { $domain = $is_https . '://' . $_SERVER['HTTP_HOST']; } ?> <url> <loc><?=htmlspecialchars($domain . '/')?></loc> <lastmod><?=date('Y-m-d')?></lastmod> <changefreq>daily</changefreq> <priority>1.0</priority> </url> <?php $sql_class = "SELECT classid, classpath, classurl FROM {$dbtbpre}enewsclass WHERE showclass=1 ORDER BY myorder"; $class_result = $empire->query($sql_class); while ($class = $empire->fetch($class_result)) { if (!empty($class['classurl'])) { $url = $class['classurl']; } else { $url = $domain . '/' . $class['classpath'] . '/'; } if (strpos($url, 'http') !== 0) { $url = $domain . '/' . ltrim($url, '/'); } ?> <url> <loc><?=htmlspecialchars($url)?></loc> <lastmod><?=date('Y-m-d')?></lastmod> <changefreq>daily</changefreq> <priority>0.8</priority> </url> <?php } ?> <?php $sql_news = "SELECT titleurl, newstime FROM {$dbtbpre}ecms_news ORDER BY newstime DESC LIMIT 9999"; $news_result = $empire->query($sql_news); while ($news = $empire->fetch($news_result)) { $url = $news['titleurl']; if (strpos($url, 'http') !== 0) { $url = $domain . '/' . ltrim($url, '/'); } ?> <url> <loc><?=htmlspecialchars($url)?></loc> <lastmod><?=date('Y-m-d', $news['newstime'])?></lastmod> <changefreq>monthly</changefreq> <priority>0.5</priority> </url> <?php } ?> <?php $sql_down = "SELECT titleurl, newstime FROM {$dbtbpre}ecms_download ORDER BY newstime DESC LIMIT 9999"; $down_result = $empire->query($sql_down); while ($down = $empire->fetch($down_result)) { $url = $down['titleurl']; if (strpos($url, 'http') !== 0) { $url = $domain . '/' . ltrim($url, '/'); } ?> <url> <loc><?=htmlspecialchars($url)?></loc> <lastmod><?=date('Y-m-d', $down['newstime'])?></lastmod> <changefreq>monthly</changefreq> <priority>0.5</priority> </url> <?php } ?> </urlset>

 

返回首页