如果在if内

时间:2012-05-19 11:21:13

标签: php wordpress if-statement

我在将if语句置于if个语句中时遇到轻微问题,例如:

<?php
$steponeimage = get_post_meta($post->ID, 'step_one_image', true);
$steponecontent = get_post_meta($post->ID, 'step_one_content', true);
$steptwoimage = get_post_meta($post->ID, 'step_two_image', true);
$steptwocontent = get_post_meta($post->ID, 'step_two_content', true);
$stepthreeimage = get_post_meta($post->ID, 'step_three_image', true);
$stepthreecontent = get_post_meta($post->ID, 'step_3_content', true);
if ($steponecontent) {
?>
<div id="processPanel" class="panel">
    <a href="#content1" label="1">Step 1</a>
<?php if ($steptwocontent) { ?>
<a href="#content2" label="2">Step Two</a>
<?php } else { ?><?php } ?>
<?php if ($stepthreecontent) { ?>
<a href="#content3" label="3">Step Three</a>
<?php } else { ?><?php } ?>
    <div id="content1">
<p><?php $images1 = $helper->imageDisplay($steponeimage , $height , $width , true , $ar[0] , false, false,'' ,'' ,false);
echo "<div class='imageholder'> $images1 </div>"; ?></p>
<p><?php echo $steponecontent; ?></p>
</div>
<?php if ($steptwocontent); { ?>
<div id="content2">
<p><?php $images2 = $helper->imageDisplay($steptwoimage , $height , $width , true , $ar[0] , false, false,'' ,'' ,false);
echo "<div class='imageholder'> $images2 </div>"; ?></p>
<p><?php echo $steptwocontent; ?></p>
</div><?php } else { ?><?php } ?>
<?php if ($stepthreecontent); { ?>
<div id="content3">
<p><?php $images3 = $helper->imageDisplay($stepthreeimage , $height , $width , true , $ar[0] , false, false,'' ,'' ,false);
echo "<div class='imageholder'> $images3 </div>"; ?></p>
<p><?php echo $stepthreecontent; ?></p>
</div><?php } else { ?><?php } ?>
</div>
<?php } else { ?>
<?php } ?>

我试图从wordpress帖子中读取帖子元数据,如果有一个步骤填充的元数据框显示了逐步信息,那么如果第二步的元数据填充在其中,则添加&#39第二步到那里,如果填好第三步的话,就加上第三步等。

我的错误是

  

解析错误:语法错误,意外T_ELSE

这是来自这里:

<p><?php echo $steptwocontent; ?></p>
</div><?php } else { ?><?php } ?>

1 个答案:

答案 0 :(得分:3)

这是你的问题:

if ($steptwocontent); {

将其更改为

if ($steptwocontent) {

编辑:

刚刚注意到你也用stepthreecontent做了同样的事情

更改

if ($stepthreecontent); {

if ($stepthreecontent) {