本人用于sitemap.xml,但不局限于此
新建 sitelink.lib.php[名字可任意命名,按规则即可],内容如下
<?php /* 获取所有分页列表的分页网址 如---> http://www.abc.com/abc/list_145_2.html http://www.abc.com/abc/list_145_3.html http://www.abc.com/abc/list_145_x.html ... */ if(!defined('DEDEINC')) exit('Request Error!'); function lib_sitelink(&$ctag,&$refObj) { global $dsql,$envs; $attlist='typeid|0,pagesize|0'; FillAttsDefault($ctag->CAttribute->Items,$attlist); extract($ctag->CAttribute->Items, EXTR_SKIP); $innertext = trim($ctag->GetInnerText()); if($typeid==0) { $typeid = ( isset($refObj->TypeLink->TypeInfos['id']) ? $refObj->TypeLink->TypeInfos['id'] : $envs['typeid'] ); } //如果没有指定每页显示多少条--->pagesize,则默认为10 if(empty($pagesize)) $pagesize=10; $dsql->Execute('me','select id,typedir from #@__arctype where ispart=0'); while($rs = $dsql->GetArray('me')){ //loop begin $typedir = str_replace('{cmspath}',$GLOBALS['cfg_basehost'],$rs['typedir']); $num=$dsql->GetOne('select count(*) as page from #@__archives where typeid='.$rs['id']); $page=$dsql->GetOne('select ceil('.$num['page'].'/'.$pagesize.') as a'); for($i=2;$i<=$page['a'];$i++){ $sitelink = '<url><loc>'.$typedir.'/list_'.$rs['id'].'_'.$i.'.html'.'</loc></url>'; $row['sitelink'] = $row['sitelink'].$sitelink; } //loop end } if(!is_array($row)) return ''; if(trim($innertext)=='') $innertext = GetSysTemplets("part_type_list.htm"); $dtp = new DedeTagParse(); $dtp->SetNameSpace('field','[',']'); $dtp->LoadSource($innertext); if(!is_array($dtp->CTags)) { unset($dtp); return ''; } else { foreach($dtp->CTags as $tagid=>$ctag) { if(isset($row[$ctag->GetName()])) $dtp->Assign($tagid,$row[$ctag->GetName()]); } $revalue = $dtp->GetResult(); unset($dtp); return $revalue; } } ?>
模版调用---->如果没有指定每页显示多少条--->pagesize,则默认为10
注---->上面--->line--->37--->$sitelink = '<url><loc>'.$typedir.'/list_'.$id.'_'.$i.'.html'.'</loc></url>\n'; 可根据具体情况自定义
{dede:sitelink pagesize='20'}
[field:sitelink/]
{/dede:sitelink}
上传至 \include\taglib\ 下即可
-------------------------------------------------------------------------------------------------------------------------------
附
www.abc.com/后台/makehtml_sitemap.php
<?php require_once(dirname(__FILE__)."/config.php"); CheckPurview('sys_MakeHtml'); require_once(DEDEINC."/arc.partview.class.php"); if(empty($dopost)) { $dopost = ''; } if($dopost=="view") { $pv = new PartView(); $templet = str_replace("{style}",$cfg_df_style,$templet); $pv->SetTemplet($cfg_basedir.$cfg_templets_dir."/".$templet); $pv->Display(); exit(); } else if($dopost=="make") { $homeFile = DEDEADMIN."/".$position; $homeFile = str_replace("\\","/",$homeFile); $homeFile = str_replace("//","/",$homeFile); $fp = fopen($homeFile,"w") or die("你指定的文件名有问题,无法创建文件"); fclose($fp); if($saveset==1) { $iquery = "update `#@__homepageset` set templet='$templet',position='$position' "; $dsql->ExecuteNoneQuery($iquery); } $templet = str_replace("{style}",$cfg_df_style,$templet); $pv = new PartView(); $GLOBALS['_arclistEnv'] = 'index'; $pv->SetTemplet($cfg_basedir.$cfg_templets_dir."/".$templet); $pv->SaveToHtml($homeFile); echo "成功更新网站地图XML:".$homeFile; echo "<br/><br/><a href='$position' target='_blank'>浏览...</a>"; exit(); } $row = $dsql->GetOne("Select * From #@__homepageset"); include DedeInclude('templets/makehtml_sitemap.htm'); ?>
www.abc.com/后台/templets/makehtml_sitemap.htm
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>主页更新向导</title> <link href="css/base.css" rel="stylesheet" type="text/css"> <link rel="stylesheet" type="text/css" media="all" href="../include/calendar/calendar-win2k-1.css" title="win2k-1" /> <script type="text/javascript" src="../include/calendar/calendar.js"></script> <script type="text/javascript" src="../include/calendar/calendar-cn.js"></script> <script language="javascript"> function SelectTemplets(fname) { var posLeft = 200; var posTop = 300; window.open("../include/dialog/select_templets.php?f="+fname, "poptempWin", "scrollbars=yes,resizable=yes,statebar=no,width=600,height=400,left="+posLeft+", top="+posTop); } </script> </head> <body background='img/allbg.gif' leftmargin='8' topmargin='8'> <table width="98%" border="0" cellpadding="3" cellspacing="1" bgcolor="#CFCFCF" align="center"> <form name="form1" action="makehtml_homepage.php" target="stafrm" method="get"> <input type="hidden" name="dopost" value="make"> <tr> <td height="28" colspan="2" background='img/wbg.gif'> <table width="98%" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="30%" height="18"><strong>sitemap更新向导:</strong></td> <td width="70%" align="right"> </td> </tr> </table> </td> </tr> <tr> <td width="177" valign="top" bgcolor="#FFFFFF">选择sitemap模板:</td> <td width="791" valign="top" bgcolor="#FFFFFF"> <input name="templet" type="text" id="templet" style="width:300" value="plus/sitemap-col.xml" readonly> </td> </tr> <tr> <td height="20" valign="top" bgcolor="#FFFFFF">主页位置:</td> <td height="20" valign="top" bgcolor="#FFFFFF"><input name="position" type="text" id="position" value="../sitemap.xml" size="30" readonly> </td> </tr> <tr style="display:none"> <td height="20" valign="top" bgcolor="#FFFFFF">相关选项:</td> <td height="20" valign="top" bgcolor="#FFFFFF"> <input name="saveset" type="radio" value="0" class="np" checked> 不保存当前选项 <input name="saveset" type="radio" class="np" value="1"> 保存当前选项 </td> </tr> <tr style="display:none"> <td height="20" valign="top" bgcolor="#FFFFFF">首页模式:</td> <td height="20" valign="top" bgcolor="#FFFFFF"><input name="showmod" type="radio" value="0" class="np" <?php echo ($row['showmod']==0)? "checked='checked'" : "";?>/> 动态浏览 <input name="showmod" type="radio" class="np" value="1" checked /> 生成静态 (或者手动删除根目录下index.html文件)</td> </tr> <tr> <td height="31" colspan="2" bgcolor="#ffffff" align="center"> <input type="submit" class='coolbg np' name="Submit" value="更新XML网站地图" /> </td> </tr> </form> <tr bgcolor="#F9FCEF"> <td height="20" colspan="2"><table width="100%"> <tr> <td width="74%">进行状态: </td> <td width="26%" align="right"> <script language='javascript'> function ResizeDiv(obj,ty) { if(ty=="+") document.all[obj].style.pixelHeight += 50; else if(document.all[obj].style.pixelHeight>80) document.all[obj].style.pixelHeight = document.all[obj].style.pixelHeight - 50; } </script> [<a href='#' onClick="ResizeDiv('mdv','+');">增大</a>] [<a href='#' onClick="ResizeDiv('mdv','-');">缩小</a>] </td> </tr> </table> </td> </tr> <tr bgcolor="#FFFFFF"> <td colspan="2" id="mtd"> <div id='mdv' style='width:100%;height:350px;'> <iframe name="stafrm" frameborder="0" id="stafrm" width="100%" height="100%"></iframe> </div> </td> </tr> </table> </body> </html>
templets/plus/sitemap-col.xml
<?xml version="1.0" encoding="UTF-8" ?> <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url><loc>{dede:global.cfg_basehost/}/</loc></url> {dede:sql sql="select * from #@__archives where ismake !=-1 and arcrank !=-2 order by pubdate desc"} <url><loc>http://www.abc.com[field:id function='GetArcurl(@me)'/]</loc></url> {/dede:sql} <url><loc>{dede:global.cfg_basehost/}/tags/</loc></url> <url><loc>http://www.abc.com/sitmap.html</loc></url> <url><loc>http://www.abc.com/today/</loc></url> <url><loc>http://www.abc.com/ask/</loc></url> {dede:sql sql="select * from #@__asktype where reid=0 and id in(1,8,15,22,30,79,81)";} <url> <loc>http://www.abc.com/ask/browser-1-[field:id /].html</loc> </url> {/dede:sql} {dede:sql sql="select * from #@__asktype where reid=1 or reid=8 or reid=15 or reid=22 or reid=30 or reid=79 or reid=81";} <url> <loc>http://www.abc.com/ask/browser-2-[field:id /].html</loc> </url> {/dede:sql} {dede:sitelink pagesize='20'} [field:sitelink/] {/dede:sitelink} {dede:channel type='top' row='10'} <url> <loc>http://www.abc.com[field:typelink /]</loc> </url> <loc>http://www.abc.com/zt/helen/</loc> </url> <url> <loc>http://www.abc.com/zt/flow-help/</loc> </url> <url> <loc>http://www.abc.com/zt/jianjie/</loc> </url> </urlset>