vendredi 2 décembre 2016

How to make php condition "If...else..." works correctly?

My fonction should be very simple but it's not so easy for me, I need help for that.

Here is my website and I use Custom fields so display into a modal box : - either an image, when there is any - or a soundcloud embed track, when there is any Never both! But both shown by a thumbnail on homepage.

This is my code which is working actually but there is some bug like, why is there a souncloud box on the page, it should be on the lightbox.

<div id="post">
        <a href="#" data-featherlight="#fl3">       

<?php
if ( get_field('music') and get_field('music') != '' ) {
?>
<iframe width="100%" height="166" scrolling="no" class="lightbox" class="frame" id="fl3" frameborder="no" src="http://ift.tt/1cM6nOR the_field('music'); ?>&amp;color=1b1e25&amp;theme_color=1b1e25&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false"></iframe> 
<?php } else { ?>



                         <div

<?php $image = get_field('image');
if( !empty($image) ): ?>

class="img" 
href="<?php  $image = get_field('image');if( !empty($image) ): ?> <?php echo $image['url']; ?>"
alt="<?php echo $image['alt']; ?> <?php endif; ?>" 
data-featherlight="image" >
                             <?php endif; ?> 

<?php } ?>


    <?php
        if ( has_post_thumbnail() ) {
        the_post_thumbnail('post-thumbnails');
        }
    ?>
            </div>
    </a>
</div>

The idea is simply : If there is a music, get the music. else Get the image

any idea? Sorry if my code is a bit dirty, I'm not a developper.

Aucun commentaire:

Enregistrer un commentaire