簡體   English   中英

如果在php echo中否則(acf true / false條件)

[英]if else in php echo (acf true/false condition)

我需要根據ACF true / false字段輸出其他鏈接。

這是我的代碼:

            $output_map[$the_ID]['map'] = '
                <div class="marker" data-lat="'.$get_google_map['lat'].'" data-lng="'.$get_google_map['lng'].'">
                    <div class="map-wrapper">
                        <div class="map-title">
                            <p><img src="'.$image_url[0].'" alt="'.get_the_title().'"></p>
                            <p class="map-object-title" href="'.get_permalink().'">'.get_the_title().'</p>


IF       <p><a class="map-button" href="'.get_permalink().'">Zum Objekt</a></p>

ELSE     <p>NO LINK</p>




                        </div>
                    </div>
                </div>';

如何在此輸出中執行if / else語句? 我已經在另一篇文章中閱讀了有關三元運算符的信息,但是我不知道該如何做。

您沒有指定ACL的定義位置,因此我假設它位於$field['asf']

然后

<a class="map-button" href="'. $field['asf'] ? get_permalink() : get_other_link() .'">

$field['asf']等於真,那么get_permalink()將被調用,否則get_other_link()將被調用

$text = '<div class="marker" data-lat="' . $get_google_map['lat'] . '" data-lng="' . $get_google_map['lng'] . '">
    <div class="map-wrapper">
        <div class="map-title">
            <p><img src="' . $image_url[0] . '" alt="' . get_the_title() . '"></p>
            <p class="map-object-title" href="' . get_permalink() . '">' . get_the_title() . '</p>';

IF $text .= '<p><a class="map-button" href="' . get_permalink() . '">Zum Objekt</a></p>';

ELSE $text .= '<p>NO LINK</p>';

$text .= '</div>
    </div>
</div>';

$output_map[$the_ID]['map'] = $text;

您可以嘗試使用這些函數ob_start()ob_get_clean() 這是代碼:

<?php $output_map[$the_ID]['map'] = ''; 
ob_start();
?>
<div class="marker" data-lat="'.$get_google_map['lat'].'" data-lng="'.$get_google_map['lng'].'">
     <div class="map-wrapper">
         <div class="map-title">
             <p><img src="'.$image_url[0].'" alt="'.get_the_title().'"></p>
                <p class="map-object-title" href="'.get_permalink().'">'.get_the_title().'</p>
  <?php if(){?>       
     <p><a class="map-button" href="'.get_permalink().'">Zum Objekt</a></p>
  <?php }else{?>
    <p>NO LINK</p>
  <?php } ?>
     </div>
   </div>
</div>
<?php 
$output_map[$the_ID]['map'] = ob_get_clean();
?>

這些函數中提供的HTML代碼可以存儲在變量中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM