WordPress.org

Ready to get started?Download WordPress

Forums

Featured Video
Problem with featured video/image (2 posts)

  1. aandagtreclame
    Member
    Posted 1 year ago #

    Hello there,

    I'd like to use the featured video plug-in to display a video in a post, but when there is no video the featured image should be displayed.

    My current code looks like this:

    <!-- Featured Image -->
    			<?php if(get_option_tree('show_featured_image') == 'Yes') : ?>
    
    					<?php if (has_post_video()) the_post_video(640,360) ?>
    
    					<?php if (has_post_thumbnail( $post->ID )) {
    
    						// Check for Sencha preferences, set the variable if the user wants it.
    						// Unused as of 1.04 for the time being until some bugs get sorted out
    				 		if (get_option_tree('sencha') == 'Yes') {
    							$sencha = 'http://src.sencha.io/';
    						} else {
    							$sencha = '';
    						} 
    
    						// Grab the URL for the thumbnail (featured image)
    						$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
    						$post_slug = str_replace(" ", "-",$post->post_name);
    
    						// Check for a lightbox link, if it exists, use that as the value.
    						// If it doesn't, use the featured image URL from above.
    						if(get_custom_field('lightbox_link')) {
    							$lightbox_link = get_custom_field('lightbox_link');
    						} else {
    							$lightbox_link = $image[0];
    						}
    
    						?>
    					<!-- <a href="<?php echo $lightbox_link; ?>" data-rel="prettyPhoto[<?php echo $post_slug; ?>]"> -->
    						<img class="aligncenter" src="<?php echo $sencha; ?><?php echo $image[0]; ?>" alt="<?php the_title(); ?>" />
    					<!-- </a> -->
    
    				<br class="clearfix" />
    				<?php } else {} ?>	 
    
    			<?php endif; ?>

    But it displays both the featured video and featured image. I've tried but I can't seem to get it the code working to;

    1. Display a video if there is an URL for the featured video entered in the post in WordPress.
    2. Display the featured image if there is NO link entered for a featured video.

    I only seem to get both to be displayed working. Anybody go a solution for this?

    Regards,
    AANDAGT

    http://wordpress.org/extend/plugins/featured-video/

  2. Alexander Hoereth
    Member
    Posted 1 year ago #

    Hey Aandagt,
    have a look at Featured Video Plus . It does exactly what you request here automatically if your theme uses the_post_thumbnail() or get_the_post_thumbnail() to display featured images. I wrote it after using the original Featured Video plugin.

    If you want to use your code, alter

    <?php if (has_post_video()) the_post_video(640,360) ?>
    <?php if (has_post_thumbnail( $post->ID )) {

    to

    <?php if (has_post_video()) the_post_video(640,360) ?>
    <?php elseif (has_post_thumbnail( $post->ID )) {

    Alex

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic