2013-06-05 112 views
-1

試圖返回$出變量問題

$out = ''; 
    $out .= '<form id="agp_upload_image_form" method="post" action="" enctype="multipart/form-data">'; 

$out .= wp_nonce_field('agp_upload_image_form', 'agp_upload_image_form_submitted'); 

    $out .= $posttile = get_option('posttitle'); 
    $out .= $postdiscription = get_option('postdiscription'); 
    $out .= $postauthor = get_option('postauthor'); 
    $out .= $postcategory= get_option('postcategory'); 
    $out .= $uploadimage= get_option('uploadimage'); 
    $out .= $posttitleenabledisables = get_option('posttitleenabledisables'); 
    $out .= $postdiscriptionenabledisable = get_option('postdiscriptionenabledisable'); 
    $out .= $postauthorenabledisable = get_option('postauthorenabledisable'); 
    $out .= $postcategoryenabledisable = get_option('postcategoryenabledisable'); 
    $out .= $uploadimageenabledisable = get_option('uploadimageenabledisable'); 
    $out .= $posttaxonomies = get_option('posttaxonomies'); 
    $out .= $enablecaptcha = get_option('captchaprivatekey'); 

if ($posttitleenabledisables == 'disable') { } else { 
    $out .= '<label id="labels" for="agp_image_caption">"'.if (isset($posttile[0])) { echo get_option('posttitle'); } else { echo 'Post Title'; } .'":</label><br/>'; 

    $out .='<input type="text" id="agp_image_caption" name="agp_image_caption" value="$agp_image_caption ;"/><br/>'; 
} 

但停留在這一點上給錯誤

$out .= '<label id="labels" for="agp_image_caption">"'.if (isset($posttile[0])) { echo get_option('posttitle'); } else { echo 'Post Title'; } .'":</label><br/>'; 

我想這回,但得到的錯誤,因爲我覺得變量不允許的if else

可以有人告訴如何解決這個問題

+0

什麼是你看到的錯誤? – Pudge601

+0

請在Dreamweaver中複製代碼,你會發現我的意思是 – Corlax

+0

..你可以通過告訴我們錯誤信息是什麼來節省我們所有的時間(包括你自己)。 – Pudge601

回答

2

你想使用的方式更改您的代碼的if/else,我想你需要一個ternary operator。如果/別的控制不能用你嘗試的方式。

嘗試:

$out .= '<label id="labels" for="agp_image_caption">"'. (isset($posttile[0]) ? get_option('posttitle') : 'Post Title') .'":</label><br/>'; 

基本上,如果其他不返回任何價值,不能在線使用。三元運算符評估爲單個值,可以與字符串連接並在任何其他表達式中內聯使用。

$cond ? $true_val : $false_val 

如果$cond評估爲true,整個語句評估爲$true_val,否則$false_val

+0

我認爲這幫助我感謝箴言:) – Corlax

+0

@SonuMeena別提了。很高興有幫助。 :) –

0

試試像

if (isset($posttile[0])) { 
    $out .= '<label id="labels" for="agp_image_caption">'. get_option('posttitle').':</label><br/>'; 
} else { 
    $out .= '<label id="labels" for="agp_image_caption">Post Title:</label><br/>'; 
} 

在你的代碼中刪除多餘的

否則容易像像

$out .= '<label id="labels" for="agp_image_caption">'.if (isset($posttile[0])) { get_option('posttitle') } else { 'Post Title' } .':</label><br/>'; 
+0

你不能在這種情況下使用回聲。只是刪除它。 – ferdynator

+0

Yah感謝你的建議 – Gautam3164

+0

@SonuMeena你試過了嗎? – Gautam3164

0

Ty Ternaryoperator。

$out .= '<label id="labels" for="agp_image_caption">"'; 
$out.= (isset($posttile[0]))? get_option('posttitle') : 'Post Title'; 
$out.='":</label><br/>'; 
0

這是因爲你在字符串concat中有一個條件。

更換

$out .= '<label id="labels" for="agp_image_caption">"'.if (isset($posttile[0])) { echo get_option('posttitle'); } else { echo 'Post Title'; } .'":</label><br/>'; 

$caption = isset($posttile[0]) ? get_option('posttitle') : "Post Title"; 
$out = '<label id="labels" for="agp_image_caption">"' . $caption . '":</label><br/>';