A-A+
DedeCms模板中使用联动类别数组
在DedeCms中,有时候会用到模板中使用联动类别的数组,主要就是在模板的使用文件中使用 $em_countrys数组,本实例应用不算是很频繁,可以试着去修改一下。
在模板中使用文件 data/enums/country.php 的$em_countrys数组
<?php
global $em_countrys;
$em_countrys = array();
$em_countrys['500'] = '纽约';
$em_countrys['1000'] = '中国';
$em_countrys['1500'] = '日本';
$em_countrys['2000'] = '法国';
?>
{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}