阅读:997回复:0

利用海洋cms DIY组件搭建动态sitemap地图教程

楼主#
更多 发布于:2021-11-06 13:04
不懂代码的可以不用看代码,直接看文字就能理解,非常简单!

1、复制根目录下 diy.php文件一份重命名为你想要的文件
例如 sitemap.php
将如下代码粘贴

<?php
require_once ("include/common.php");
$cs=$_SERVER["REQUEST_URI"];
if($GLOBALS['cfg_mskin']==3 AND $GLOBALS['isMobile']==1){header("location:$cfg_mhost$cs");}
if($GLOBALS['cfg_mskin']==4 AND $GLOBALS['isMobile']==1){header("location:$cfg_mhost");}
function php_self(){
    $php_self=substr($_SERVER['PHP_SELF'],strrpos($_SERVER['PHP_SELF'],'/')+1);
 $php_self=str_replace('.php','',$php_self);
    return $php_self;
}
$phpself=php_self();
require_once sea_INC."/main.class.php";
echoIndex();
function echoIndex()
{
 global $cfg_iscache,$t1,$phpself;
 $cacheName="parsed_".$phpself.$GLOBALS['cfg_mskin'].$GLOBALS['isMobile'];
 $templatePath="/templets/".$GLOBALS['cfg_df_style']."/".$GLOBALS['cfg_df_html']."/".$phpself.".xml";
 if($GLOBALS['cfg_mskin']!=0 AND $GLOBALS['cfg_mskin']!=3 AND $GLOBALS['cfg_mskin']!=4  AND $GLOBALS['isMobile']==1)
 {$templatePath="/templets/".$GLOBALS['cfg_df_mstyle']."/".$GLOBALS['cfg_df_html']."/".$phpself.".xml";}
 if($cfg_iscache){
 if(chkFileCache($cacheName)){
 $indexStr = getFileCache($cacheName);
 }else{
 $indexStr = parseIndexPart($templatePath);
 setFileCache($cacheName,$indexStr);
 }
 }else{
 $indexStr = parseIndexPart($templatePath);
 }
 $indexStr=str_replace("{seacms:member}",front_member(),$indexStr);
 echo str_replace("{seacms:runinfo}",getRunTime($t1),$indexStr) ;
}
function parseIndexPart($templatePath)
{
 global $mainClassObj;
 $content=loadFile(sea_ROOT.$templatePath);
 $content=$mainClassObj->parseTopAndFoot($content);
 $content=replaceCurrentTypeId($content,-444);
 $content=$mainClassObj->parseSelf($content);
 $content=$mainClassObj->parseHistory($content);
 $content=$mainClassObj->parseGlobal($content);
 $content=$mainClassObj->parseAreaList($content);
 $content=$mainClassObj->parseNewsAreaList($content);
 $content=$mainClassObj->parseMenuList($content,"",$currentTypeId);
 $content=$mainClassObj->parseVideoList($content,$currentTypeId,'','');
 $content=$mainClassObj->parseNewsList($content,$currentTypeId,'','');
 $content=$mainClassObj->parseTopicList($content);
 $content=$mainClassObj->parseLinkList($content);
 $content=$mainClassObj->parseIf($content);
 header("Content-type:text/xml");
 return $content;
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////
说明:其实就是 将.html  修改成.xml   另外在在 71行 增加 header("Content-type:text/xml"); 代码
页可以不将 .html 修改成.xml


2、模板页制作
我们之前将html修改成xml了 那么就需要创建对应XML文件
例如: sitemap.xml   在  根目录//templets/模板目录/html/   下创建  如没有修改.html 那么直接创建 sitemap.html
3、粘贴代码

<?xml version="1.0" encoding="utf-8"?>
  <urlset>
{seacms:videolist type=all num=1000  order=time}
    <url>
        <loc>http://你自己的域名/[videolist:link]</loc>
        <lastmod>[videolist:time style=yyyy-mm-dd]></lastmod>
        <changefreq>always</changefreq>
        <priority>0.8</priority>
 
 </url>
{/seacms:videolist}
  </urlset>
/////////////////////////////////////////////////////////////////////////////////////////////////////////
上面的1000是条数,你可以根据自己情况修改。
这样就实现了动态 地图
/////////////////////////////////////////////////////////////////////////////////////////////////////////
注:新闻模板只需要修改 标签  videolist 替换成  newslist,专题 videolist替换成 topiclist        
专题的时间:tiem替换成 addtime
/////////////////////////////////////////////////////////////////////////////////////////////////////////
最后的最后添加伪静态规则
rewrite ^/sitemap.xml$ /sitemap.php last;
完成
直接访问  http://你的域名.com/sitemap.xml  即可
/////////////////////////////////////////////////////////////////////////////////////////////////////////
代写插件,你有什么好的想法可以联系我付费解决。
另出  海洋CMS 自动评论插件、 海洋cms专题插件及发布模块
Q:7377080 都很忙闲聊勿扰!~
[lzwwy于2021-11-06 13:08编辑了帖子]
游客

返回顶部