我有一个demo swicher脚本。 和演示细节写在arry像这样:
array ("id" => "آکادو",
"link" => "acadu",
"url" => "http://demo.domain.ir/template/jm-news-3/",
"preview" => "http://localhost/demo/fbar//screen/flayz.jpg",
"j2" => "joomla2.5",
"j2_color" => "8351a8",
"j3" => "joomla3",
"j3_color" => "c29413",
"ddn" => "http://themeforest.net/user/designingmedia/portfolio?ref=designingmedia"
)
身体j2&中的j3 elemans在2 span标签中调用吹码:
<?php
foreach ($theme_array as $i => $theme) :
echo '<li class="button_a">
<a href="#" rel="' . $theme['url'] . ',' . $theme['ddn'] . ','.$theme['link'].'">' .
$_SESSION['currentthemename']= ucfirst($theme['id']) .' <span style="background:#'.$theme['j2_color'].'">'.$theme['j2'].'</span><span style="background:#'.$theme['j3_color'].'">'.$theme['j3'].'</span></a>';
if(isset($theme['preview'])){
echo '<img alt="" class="preview" src="';
if(strpos($theme['preview'], 'http://') === false){
echo 'product_previews/'.$theme['preview'];
}
else echo $theme['preview'];
echo '">';
$_SESSION['currentthemename'] =$theme['url'];
$current_theme=$_SESSION['currentthemename'];
}
echo '</li>';
endforeach;
?>
当我们的一个演示同时具有这两个演示时,我们不会有任何问题。但是当我的一个演示中有一个这个elemans j2或j3时,其他没有任何背景的eleman将被显示但我们不想显示。 我们需要更改此代码,当演示中的一个eleman为空时,跨越标签,它完全不显示
答案 0 :(得分:0)
你可以改变:
echo '<li class="button_a">
<a href="#" rel="' . $theme['url'] . ',' . $theme['ddn'] . ','.$theme['link'].'">' .
$_SESSION['currentthemename']= ucfirst($theme['id']) .' <span style="background:#'.$theme['j2_color'].'">'.$theme['j2'].'</span><span style="background:#'.$theme['j3_color'].'">'.$theme['j3'].'</span></a>';
到
echo '<li class="button_a">
<a href="#" rel="' . $theme['url'] . ',' . $theme['ddn'] . ','.$theme['link'].'">' .
$_SESSION['currentthemename']= ucfirst($theme['id']) .'
'.(($theme['j2']=='any-text')?'<span style="background:#'.$theme['j2_color'].'">'.$theme['j2'].'</span>':"").'
'.(($theme['j3']=='any-text2')?'<span style="background:#'.$theme['j3_color'].'">'.$theme['j3'].'</span>':"").'
</a>';