元素模板为您解答:
//获取颜色拼音 functionget_yanse_pinyin($color){ $dyb=array( '红色'=>'hongse', '黄色'=>'huangse', '白色'=>'baise', '绿色'=>'lvse', '青色'=>'qingse', '蓝色'=>'lanse', '紫色'=>'zise', '黑色'=>'heise', '棕色'=>'zongse', '粉色'=>'fense', '橙色'=>'chengse', '灰色'=>'huise', '炫彩'=>'xuancai', ); if(array_key_exists($color,$dyb)){ return$dyb[$color]; }else{ return''; } }
把这个函数放到userfun.php里
模板里需要调用的时候类似<?=get_yanse_pinyin($fr[1])?>
list.var里调用示例:
$tagstr=dp_InfoTag($r['classid'],$r['id'],'| ',5); $a=explode('|',$r[chicun]); foreach($a as $key=>$val) { if($key>0 && $key<(count($a)-1)) { $sizeimg.=''.$val.''; } } $fr=explode("|",$r[chicun]); $a=explode('|',$r[color]); foreach($a as $key=>$val) { if($key>0 && $key<(count($a)-1)) { $colorimg.=''.$val.''; } } $fr=explode("|",$r[color]); $listtemp=' <li> <span class="imgxxs bzfbl"><a href="/size/[!--classid--]/13/'.$sizeimg.'/">'.$sizeimg.'</a></span> <span class="imgxxs bzcolor"><a href="/color/[!--classid--]/13/'.$fr[1].'/" target="_blank">'.get_yanse_pinyin($fr[1]).'</a> <a href="/color/[!--classid--]/13/'.$fr[2].'/" target="_blank">'.get_yanse_pinyin($fr[2]).'</a></span> <a href="[!--titleurl--]" class="imgw" style="display: block;" target="_blank"> <img lazysrc="[!--titlepic--]" lazysrc2x="[!--titlepic--] 2x" width="221" height="362" alt="[!--title--]" /> </a> <div class="tips">'.$tagstr.' </div> </li> ';