-1

$out を返そうとしています

$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/>';

私はこれを返したいのですが、変数が許可されていないと思うのでエラーが発生します

誰かがこれを修正する方法を教えてもらえますか

4

4 に答える 4

2

if/else を使用しようとしている方法では、三項演算子が必要だと思います。If/else コントロールは、あなたが試みている方法では使用できません。

試す:

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

基本的に、if-else は値を返さず、インラインで使用できません。三項演算子は単一の値に評価され、文字列と連結して、他の式でインラインで使用できます。

$cond ? $true_val : $false_val

$condが に評価される場合true、ステートメント全体が に評価され、それ以外の場合は に評価され$true_valます$false_val

于 2013-06-05T10:49:13.610 に答える
0

Ty 三元演算子。

$out .= '<label id="labels" for="agp_image_caption">"';
$out.= (isset($posttile[0]))? get_option('posttitle') : 'Post Title';
$out.='":</label><br/>';
于 2013-06-05T10:50:13.913 に答える
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/>';
于 2013-06-05T10:50:48.460 に答える
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/>';
}

あなたのコードで余分な"

Orelse のようにコードを次のように変更します

$out .= '<label id="labels" for="agp_image_caption">'.if ( isset($posttile[0])) { get_option('posttitle') } else { 'Post Title' } .':</label><br/>';
于 2013-06-05T10:46:21.657 に答える