显示基于数据库可用性的方面



我们的一些产品没有视频& &;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 -双- w - p - 10 - 250 - v/

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