我正在创建一个for循环,我希望条件是这样的:
if(get_field('top', $post->ID) == "Yes")
{
$HeadClass = "first";
$priority = 1;
}
else
{
$priority = 2;
$HeadClass = "second";
}
switch($HeadClass)
{
case "first":
$ImgHolderStyle = 'style="position:relative;height:300px;background:#212121;"';
$ImgStyle = 'style="position:absolute;left:192px;" src="images/img1.jpg" width="300" height="300"';
$TitleBox = 'title-box';
$TitleBg = 'bg';
$NamedClass= '';
$TitleNewsClass= '';
$PostTitleClass = '';
$View = true;
$ExtraClass = "888";
break;
case "second":
$ImgHolderStyle = 'style="width:235px;height:276px;"';
$ImgStyle = 'width="240" height="276"';
$TitleBox = '';
$TitleBg = '';
$View = false;
$ExtraClass = "";
break;
}
在上面的代码中我想要IF
条件运行直到它的真实,然后它转到其他地方。我的意思是根据$HeadClass = "first";
的出现只有当这个变为假时才转到ELSE
。
我得到的输出是什么:
<div class="first"></div>
<div class="second"></div>
<div class="second"></div>
<div class="first"></div>
我想成为的是:
<div class="first"></div>
<div class="first"></div>
<div class="second"></div>
<div class="second"></div>
答案 0 :(得分:0)
$priority = 1;
while( .... ) {
if ( 1===$priority && 'Yes'!=get_field('top', $post->ID) ) {
$priority = 2;
}
switch($priority) {
case 1:
$HeadClass = 'first';
$ImgHolderStyle = 'style="position:relative;height:300px;background:#212121;"';
// ...
break;
case 2:
$HeadClass = "second";
$ImgHolderStyle = 'style="width:235px;height:276px;"';
// ...
break;
}
}