我們的某些產品沒有視頻和 360 度全景照片。
通過functions.php,我們已經成功地將360 度全景照片和視頻按鈕添加到我們的產品頁面,現在我們只想在有可用資料的情況下顯示這些視頻。
這是 features.php 中我們在 functions.php 中呼叫的代碼:
<div class="visual-content-buttons">
<a class="image-button" href="<?php echo get_post_meta($product->id, 'video', true); ?>" data-featherlight="iframe"><img src="https://leckys.com.au/wp-content/uploads/2021/09/360-green-2.png" alt="360 Photo">Video</a>
<a class="image-button" href="<?php echo get_post_meta($product->id, '360_photo', true); ?>" data-featherlight="iframe"><img src="https://leckys.com.au/wp-content/uploads/2021/09/360-green-2.png" alt="360 Photo">360 Photo</a>
</div>
如果資料可用,我們會通過 id, 'video', true) 獲取資料;?>
我們想在那里添加一些東西,以便在沒有可用資料時不顯示按鈕。
請參閱此鏈接以獲取當前外觀的示例:
有可用資料:https : //leckys.com.au/product/drill-bit-twist-jobber-hss-5-32/
沒有可用資料:https : //leckys.com.au/product/socket-swt-twin-wp-10a-250v/
uj5u.com熱心網友回復:
由于get_post_meta如果未找到視頻或照片,則回傳一個空字串,因此您可以執行一個簡單的if陳述句以僅顯示!empty(非空)。
<?php
$video_href = get_post_meta($product->id, 'video', true);
$photo_href = get_post_meta($product->id, '360_photo', true);
?>
<div class="visual-content-buttons">
<?php
if (!empty($video_href)) {
?>
<a class="image-button" href="<?php echo $video_href; ?>" data-featherlight="iframe"><img src="https://leckys.com.au/wp-content/uploads/2021/09/360-green-2.png" alt="Video">Video</a>
<?php
}
if (!empty($photo_href)) {
?>
<a class="image-button" href="<?php echo $photo_href; ?>" data-featherlight="iframe"><img src="https://leckys.com.au/wp-content/uploads/2021/09/360-green-2.png" alt="360 Photo">360 Photo</a>
<?php
}
?>
</div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/328784.html
標籤:php WordPress的 求购
