php $image = get_field( 'image' ) // 如果 // 否则
php $image = get_field( 'image' ) // if // else
如果没有使用替代图片的图片,我需要查询。
<?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 张图像中的四张。
我想我在某处的“其他查询”中有错误。
因为如果我将默认图像与实际产品图像交换,那么它就可以工作..当然这没有意义;)
我觉得有用!!!
我把整个代码又“干净”地写了一遍!
感谢大家的支持!
<?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();
}
如果没有使用替代图片的图片,我需要查询。
<?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 张图像中的四张。 我想我在某处的“其他查询”中有错误。 因为如果我将默认图像与实际产品图像交换,那么它就可以工作..当然这没有意义;)
我觉得有用!!!
我把整个代码又“干净”地写了一遍!
感谢大家的支持!
<?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();
}