问题描述
如果没有使用替代图像的图像,我需要查询。
<?PHP $angebot_17 = get_field( 'angebot_17' ); ?>
<?PHP if ( $angebot_17 ) : ?>
<?PHP $post = $angebot_17; ?>
<?PHP $image = get_field( 'image' ); ?>
<?PHP if ( $image ) { ?>
<a href="<?PHP the_permalink(); ?>">
<img width="300" height="300" src="<?PHP the_field('image'); ?>" alt="<?PHP echo esc_attr( $image['alt'] ); ?>" class="img-responsive product-img wp-post-image Box_image" />
<?PHP $lager = get_field ('lager'); ?>
<?PHP if ( $lager) { ?>
<span class="goods_label" style="background-color: #00CC99;color: #ffffff;bottom:8px;border-color: #00CC99;">
<span>Versand aus Deutschland</span>
</span>
<?PHP } ?>
</a>
<?PHP } ?>
<?PHP else: ?>
<img width="300" height="300" src="/wp-content/uploads/2019/09/cropped-logo_512x512-4.png" alt="<?PHP echo esc_attr( $image['alt'] ); ?>" />
<span class="goods_label" style="background-color: red;color: #ffffff;bottom:8px;">
<span>Leider kein Bild vorhanden</span>
</span>
<?PHP wp_reset_postdata(); ?>
<?PHP endif; ?>
疯狂的是,它可以处理18张图像中的4张。 我认为某个地方的“其他查询”中有错误。 因为如果我将默认映像与实际产品映像交换,那么它就可以正常工作..但那当然没有意义;)
解决方法
我认为它可行!
我再次“干净”地编写了整个代码!
感谢所有支持!
<?php
$angebot_1 = get_field( 'angebot_1' );
if ($angebot_1) {
$post = $angebot_1;
$image = get_field( 'image' );
if ($image) {
echo '
<img
width="300"
height="300"
src="' . esc_url( $image['url'] ) .'"
alt="' . esc_attr( $image['alt'] ) . '"
class="img-responsive product-img wp-post-image box_image" /> ';
$lager = get_field ('lager');
if ($lager) {
echo '<span
class="goods_label"
style="background-color: #00CC99;color: #ffffff;bottom:8px;border-color: #00CC99;">
<span>Versand aus Deutschland</span>
</span> ';
}
}
else {
echo '<img
width="300"
height="300"
src="/wp-content/uploads/2019/09/cropped-Logo_512x512-4.png"
alt="'. esc_attr( $image['alt'] ).'" /> ';
echo '<span
class="goods_label" style="background-color: red;color: #ffffff;bottom:8px;">
<span>Leider kein Bild vorhanden</span>
</span> ';
}
wp_reset_postdata();
}