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 } }
I also have a plugin (Featured Video Plus) which allows me to use a youtube video as a featured video instead of an image. It has certain PHP codes and I’ve managed to replace the featured image succesfully with a video.
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 } else (has_post_video( $post_id )){ ?> <div id="post-thumbnail"> <?php echo get_the_post_video( $post_id, $size )?> </div> <?php } }
- The topic ‘If else statement to either show an image or a video’ is closed to new replies.