我有多个if语句用于标题显示。如果该字段为空,我该如何隐藏标题?我知道怎么做更简单!空但不是为了这个。
澄清......
总会有一个“列出”的变量,但并不总是一个“经纪”变量。当“broker”变量为空时,我不希望显示标题。因此,必须检查“经纪人”,如果存在“已列出”变量,则返回空状态。如果“broker”不为空,那么它必须根据“列出”它返回一个特定的标题。
{{1}}
答案 0 :(得分:0)
global $post; $listed = get_post_meta($post->ID,'listed',true);
if(isset($listed)&&$listed!=""){
if( $listed == 'Sold' ) { echo ' <div class="more-information">Sold By</div><li> [broker] '; }
else if( $listed == 'For Sale' ) { echo ' <div class="more-information">Contact Information </div><li> [broker]'; }
else if( $listed == 'Not For Sale' ) { echo ' <div class="more-information">Last Active Agent </div><li> [broker]'; }
else if( $listed == 'Contingent or Pending Sale' ) { echo ' <div class="more-information">If interested, contact agent for current status. </div><li> [broker]'; }
else if( $listed == 'Demolished' ) { echo '<li> '; }
else{
//Default case i.e. do nothing
//Nothing here to display
}
}
else{
//Default case i.e. do nothing
//Nothig here
}
你没有默认情况。见上面的代码。您只是使用如果是这样,除了这些条件之外没有定义默认情况。
您也可以使用switch ...case
语句作为默认条件。
if(condition){
//do something
}
else if(condition){
//do something
}
else if(condition){
//do something
}
else{
//this is default case if your condition does not true with any of the above if conditions
//Here in your case will not be anything i.e. dont echo anything
}
答案 1 :(得分:0)
您是否尝试过检查变量?
<?php
global $post;
$listed = get_post_meta($post->ID,'listed',true);
if(isset($broker) AND $broker AND $listed)
{
if( $listed == 'Sold' ) { echo ' <div class="more-information">Sold By</div><li> [broker] '; }
if( $listed == 'For Sale' ) { echo ' <div class="more-information">Contact Information </div><li> [broker]'; }
if( $listed == 'Not For Sale' ) { echo ' <div class="more-information">Last Active Agent </div><li> [broker]'; }
if( $listed == 'Contingent or Pending Sale' ) { echo ' <div class="more-information">If interested, contact agent for current status. </div><li> [broker]'; }
if( $listed == 'Demolished' ) { echo '<li> '; }
}
else
{
// Echo nothing
echo "";
}
答案 2 :(得分:0)
这就是修复它的原因。
public function hookDisplayAfterThemeInstallation($params)
{
$theme_name = $params['theme_name'];
if ($theme_name != 'mythemename') {
return false;
}
// Enable Move JS to bottom setting
Configuration::updateValue('PS_JS_DEFER', 1);
// Optional text or html to display
return 'Your settings have been changed';
}