繁体   English   中英

运行IF直到其为真,然后转到其他PHP

[英]Run IF till its true then goto Else PHP

我正在创建一个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

我得到的ID是什么输出:

 <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> 

$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;
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM