|
本人用于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 dede_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 dede_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\ 下即可
|
|