mardi 11 août 2020

php $image = get_field( 'image' ) // if // else

I need an inquiry if there is no image that an alternative image is used.

<?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; ?>

the crazy thing is that it works on four out of 18 images. I think I have an error in the "else query" somewhere. Because if I swap the defalut image with the actual product image, then it works .. but of course that is not meaningful;)

Aucun commentaire:

Enregistrer un commentaire