Conditional statement for post & video thumbnails.
-
I’m not the best with php, and having some problems getting a conditional statement to work.
I’m using Video Thumbnails to generate thumbnails for videos. I’m using its conditional statement to only show a thumbnail if it has a video thumbnail, rather than it displaying its default one. However, in the even that no thumbnail is there I want the post thumbnail to display.
I’m using a version of post thumbnail code to only generate the url of the post thumbnail, and both are place as inline css background images. However I also want different background sizes depending on which thumbnail is displayed.
Right now what I’m using is messy:
<div class="post-image" style="background-image: url( <?php if (has_post_thumbnail( $post->ID ) ): ?> <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?> <?php echo $image[0]; ?> <?php endif; ?> ); <?php if( ( $video_thumbnail = get_video_thumbnail() ) != null ) { echo " background-image: url(" . $video_thumbnail . ");"; } ?> "><a href="<?php the_permalink() ?>"></a></div>
My goal
If video thumbnail:
background-image: url('video.png'); background-size: 180%;
If post thumbnail:
background-image: url('post.png'); background-size: 100%;
I’ve tried to put together the conditional statement to only generate the background css based on the thumbnail that is present, but as I said, I’m not that good with php.
Could I get some help from someone? Thanks so much ??
- The topic ‘Conditional statement for post & video thumbnails.’ is closed to new replies.