If else statement to either show an image or a video
-
I have a template which shows the featured image in the following way (I editted the original code to suit my needs):
<?php if ( is_singular() && is_main_query() ) { if ( of_get_option('blog_single_thumbnail' ) == '1' && has_post_thumbnail() ) { ?> <div id="post-thumbnail"> <img src="<?php echo aq_resize( wp_get_attachment_url( get_post_thumbnail_id() ), wpex_img('blog_post_crop') ) ?>" alt="<?php echo the_title(); ?>" /> </div> <?php } }
Now I want an if statement which shows the video if the plugin is used. I’m having trouble with the proper syntax. How do I write it properly?
<?php if ( is_singular() && is_main_query() ) { if ( of_get_option('blog_single_thumbnail' ) == '1' && has_post_thumbnail() ) { ?> <div id="post-thumbnail"> <img src="<?php echo aq_resize( wp_get_attachment_url( get_post_thumbnail_id() ), wpex_img('blog_post_crop') ) ?>" alt="<?php echo the_title(); ?>" /> </div> <?php } elseif (has_post_video( $post_id ));{ ?> <div id="post-thumbnail"> <?php echo get_the_post_video( $post_id, $size ); ?> </div> <?php } }
Right now it shows the video and image together: https://www.hallometmirel.nl/emd (youtube post)
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘If else statement to either show an image or a video’ is closed to new replies.