A-A+

DedeCms模板中使用联动类别数组

2012年10月09日 PHP开源系统 暂无评论 阅读 182 views 次

在DedeCms中,有时候会用到模板中使用联动类别的数组,主要就是在模板的使用文件中使用 $em_countrys数组,本实例应用不算是很频繁,可以试着去修改一下。

在模板中使用文件 data/enums/country.php 的$em_countrys数组

<?php 
global $em_countrys; 
$em_countrys = array(); 
$em_countrys&#91;'500'&#93; = '纽约'; 
$em_countrys&#91;'1000'&#93; = '中国'; 
$em_countrys&#91;'1500'&#93; = '日本'; 
$em_countrys&#91;'2000'&#93; = '法国'; 
?> 

{dede:include runphp='yes' file='../data/enums/country.php'/} //导
//入data/enums/country.php文件 
{dede:field runphp='yes'} //运行PHP代码 
global $em_countrys; //声明全局变量 
if(!emptyempty($em_countrys) && is_array($em_countrys)) 
{ 
foreach($em_countrys as $k => $countrys) 
{ 
//使用 @me 表示当前的值 
@me .= "<a href=\"search.php?country={$countrys}\">".$countr
ys."</a> ";
} 
} 
{/dede:field}
标签:

给我留言