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;)
i think it works!!!
I wrote the whole code again "cleanly"!
Thanks for all the support!
<?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();
}
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.