Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP If语句始终传递第一个语句_Php_If Statement - Fatal编程技术网

PHP If语句始终传递第一个语句

PHP If语句始终传递第一个语句,php,if-statement,Php,If Statement,我对这个if语句有一个问题,它位于wordpress循环中。第一个if语句--if($caption==“1”)似乎可以工作,但第二个if语句似乎总是通过,即使$image\u title没有==这些字符串 foreach ( $images as $attachment_id => $attachment ) { // $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);

我对这个if语句有一个问题,它位于wordpress循环中。第一个if语句--
if($caption==“1”)
似乎可以工作,但第二个if语句似乎总是通过,即使
$image\u title
没有==这些字符串

foreach ( $images as $attachment_id => $attachment ) {

        // $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
        $image_title = $attachment->post_title;
        $caption = $attachment->post_excerpt;
        $description = $attachment->post_content;

        $img_url = get_post_meta( $attachment->ID, '_gallery_link_url', true ); //WP Gallery Custom Links extra URL field


        if ( $caption == "1") { 

                echo '<div class="imagewrapb">';

                    if ($image_title == "Branding" or "Print" or "Digital" or"Packaging") {
                        echo '<h3>'.$image_title.'</h3>';
                        echo wp_get_attachment_image( $attachment_id, '' );
                        echo '<a href="'.$img_url.'">'.'<div class="hover">'.$description.'</div>'.'</a>';

                    var_dump($image_title);

                    }

                    else if ($image_title == "Twitter") {
                        echo '<h3>'.$image_title.'</h3>';
                        echo wp_get_attachment_image( $attachment_id, '' );
                        echo '<div class="twitterfeed"><h2>@V_IX</h2><ul id="twitter_update_list"><li>Twitter feed loading</li></ul></div>';
                    }                   

                    else if ($image_title == "Facebook") {
                        echo '<h3>'.$image_title.'</h3>';
                        echo wp_get_attachment_image( $attachment_id, '' );
                        echo '<div class="facebookfeed">';
                        include 'facebook.php';
                        echo '</div>';
                    }

                    else {

                        if ( !empty($img_url) /*img_url exists*/ ){

                            echo '<h3>'.$image_title.'</h3>';

                            if ( !empty($description) /*description exists*/ ){
                                echo wp_get_attachment_image( $attachment_id, '' );
                                echo '<a href="'.$img_url.'">'.'<div class="hover">'.$description.'</div>'.'</a>';
                            }

                            else {
                                echo '<a href="'.$img_url.'">';
                                echo wp_get_attachment_image( $attachment_id, '' );
                                echo '</a>';

                            }
                        }   

                        else  { /*img_url doesnt exist*/

                            echo '<h3>'.$image_title.'</h3>';

                            if ( !empty($description) /*description exists*/ ){
                                echo wp_get_attachment_image( $attachment_id, '' );
                                echo '<div class="hover">'.$description.'</div>';
                            }

                            else {
                                echo wp_get_attachment_image( $attachment_id, '' );
                            }
                        }

                    }

                echo '</div>';


        }

        else {
                    echo '<div class="imagewrap">';

                    if ($image_title == "Branding" || "Print" || "Digital" || "Packaging") {
                        echo '<h3>'.$image_title.'</h3>';
                        echo wp_get_attachment_image( $attachment_id, '' );
                        echo '<a href="'.$img_url.'">'.'<div class="hover">'.$description.'</div>'.'</a>';
                    }

                    else if ($image_title == "Twitter" ) {
                        echo '<h3>'.$image_title.'</h3>';
                        echo wp_get_attachment_image( $attachment_id, '' );
                        echo '<div class="twitterfeed"><h2>@V_IX</h2><ul id="twitter_update_list"><li>Twitter feed loading</li></ul></div>';
                    }                   

                    else if ($image_title == "Facebook") {
                        echo '<h3>'.$image_title.'</h3>';
                        echo wp_get_attachment_image( $attachment_id, '' );
                        echo '<div class="facebookfeed">';
                        include 'facebook.php';
                        echo '</div>';
                    }

                    else {

                        if ( !empty($img_url) /*img_url exists*/ ){

                            echo '<h3>'.$image_title.'</h3>';

                            if ( !empty($description) /*description exists*/ ){
                                echo wp_get_attachment_image( $attachment_id, '' );
                                echo '<a href="'.$img_url.'">'.'<div class="hover">'.$description.'</div>'.'</a>';
                            }

                            else {
                                echo '<a href="'.$img_url.'">';
                                echo wp_get_attachment_image( $attachment_id, '' );
                                echo '</a>';

                            }
                        }   

                        else  { /*img_url doesnt exist*/

                            echo '<h3>'.$image_title.'</h3>';

                            if ( !empty($description) /*description exists*/ ){
                                echo wp_get_attachment_image( $attachment_id, '' );
                                echo '<div class="hover">'.$description.'</div>';
                            }

                            else {
                                echo wp_get_attachment_image( $attachment_id, '' );
                            }
                        }

                    }

                echo '</div>';

        }
    }
foreach($attachment形式的图像\u id=>$attachment){
//$alt=get\u post\u meta($attachment->ID,'.\u wp\u attachment\u image\u alt',true);
$image\u title=$attachment->post\u title;
$caption=$attachment->post_摘录;
$description=$attachment->post_内容;
$img\u url=get\u post\u meta($attachment->ID,'.\u gallery\u link\u url',true);//WP gallery自定义链接额外url字段
如果($caption==“1”){
回声';
如果($image_title==“品牌”或“印刷”或“数字”或“包装”){
回显“.$image_title.”;
echo wp_get_attachment_image($attachment_id');
回声';
变量转储($image\u title);
}
else if($image_title==“Twitter”){
回显“.$image_title.”;
echo wp_get_attachment_image($attachment_id');
echo'@V_IX
  • 推特提要加载; } else if($image_title==“Facebook”){ 回显“.$image_title.”; echo wp_get_attachment_image($attachment_id'); 回声'; 包括“facebook.php”; 回声'; } 否则{ 如果(!empty($img\u url)/*img\u url存在*/){ 回显“.$image_title.”; 如果(!empty($description)/*存在description*/){ echo wp_get_attachment_image($attachment_id'); 回声'; } 否则{ 回声'; } } 否则{/*img_url不存在*/ 回显“.$image_title.”; 如果(!empty($description)/*存在description*/){ echo wp_get_attachment_image($attachment_id'); 回显“.$description.”; } 否则{ echo wp_get_attachment_image($attachment_id'); } } } 回声'; } 否则{ 回声'; 如果($image|u title==“品牌”| |“打印”| |“数字”| |“包装”){ 回显“.$image_title.”; echo wp_get_attachment_image($attachment_id'); 回声'; } else if($image_title==“Twitter”){ 回显“.$image_title.”; echo wp_get_attachment_image($attachment_id'); echo'@V_IX
    • 推特提要加载; } else if($image_title==“Facebook”){ 回显“.$image_title.”; echo wp_get_attachment_image($attachment_id'); 回声'; 包括“facebook.php”; 回声'; } 否则{ 如果(!empty($img\u url)/*img\u url存在*/){ 回显“.$image_title.”; 如果(!empty($description)/*存在description*/){ echo wp_get_attachment_image($attachment_id'); 回声'; } 否则{ 回声'; } } 否则{/*img_url不存在*/ 回显“.$image_title.”; 如果(!empty($description)/*存在description*/){ echo wp_get_attachment_image($attachment_id'); 回显“.$description.”; } 否则{ echo wp_get_attachment_image($attachment_id'); } } } 回声'; } }
将if语句更改为(我认为是什么?)正确-
if($image_title==“Branding”)| |($image_title==“Print”)| |($image_title==“Digital”)|($image_title==“Packaging”){
-似乎没有显示带有“Branding”等字符串的变量

if ($image_title == "Branding" or "Print" or "Digital" or "Packaging")
必须是:

if ($image_title == 'Branding' || $image_title == 'Print' || $image_title == 'Digital' || $image_title == 'Packaging')
必须是:

if ($image_title == 'Branding' || $image_title == 'Print' || $image_title == 'Digital' || $image_title == 'Packaging')

如果
$image\u title
的值是这4个值中的一个,那么它应该可以工作..如果
$image\u title
的值是这4个值中的一个,那么它应该可以工作..原因是你实际上说如果(“打印”),非空字符串将始终为true。此外,如果您必须检查某个值是否是多个不同值中的一个,则可以在_数组中使用
,例如,
if(在_数组中($image_title,array('Branding','Print','Digital','Packaging'){}
非常有效,谢谢。原因是您实际说的是“if”(“Print”),且非空字符串将始终为true。此外,如果必须检查某个值是否是多个不同值中的一个,则可以在数组中使用
,例如