I’d like to implement an if – ifelse – else condition.

  • if condition is for posts having an image (standard)
  • ifelse condition is for video-posts without images. I added a custum field to upload a videostill-image to be shown as thumbnail in the news-section on frontpage instead.
  • else is the fallback image for posts without any image

I tried the following but it doesn’t work and my php-skills are rudimentary. Here’s a link to the section: http://parkfreunde-weissensee.berlin/#news

        <div class="list-article-thumb-mobile">
            <a href="<?php echo esc_url( get_permalink() ); ?>">
                <?php
                if ( has_post_thumbnail( ) ) {
                    the_post_thumbnail( 'onepress-blog-small' );
                } 

                elseif ( get_field ( 'post_thumbnail_home' ) ) {
                    the_field ( 'post_thumbnail_home' );
                }

                else {
                    echo '<img alt="" src="'. get_template_directory_uri() . '/assets/images/placholder2.png' .'">';
                }
                ?>
            </a>
        </div>

Read more here: WordPress custom fields if ifelse else condition


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: