• Resolved krill3

    (@krill3)


    The problem:

    I’m doing some overly fancy PHP work with my featured images/videos, I don’t use default tags giving you an <img> I’m using this:

    <?php if (has_post_thumbnail( $post->ID ) ): ?>
    <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
    <?php endif; ?>
        <div class="overlayImg" style="background-image: url('<?php echo $image[0]; ?>')">
        </div>

    To give me a div with the image as a background, I realize I can’t put a video as a div’s background, instead I want to do some custom stuff on posts with featured videos, problem is that there is no way to tell which posts have it and which don’t using this plugin without using wonky after the fact JS or me editing the plugin, which I don’t feel confident/competent/comfortable doing.

    Suggested solution:

    Adding a custom class to posts that have a featured video would greatly help, and something like “has_post_thumbnail” but for videos would also be useful to allow me to pick video/picture in the PHP.

    https://www.ads-software.com/plugins/featured-video-plus/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Alex

    (@ahoereth)

    There is a has_post_video($post_id) function. If no $post_id is given the current post’s ID will be used. See plugin description.

    Thread Starter krill3

    (@krill3)

    Doh, sorry didn’t spot that, works a treat:

    <?php if (has_post_video($post->ID)): ?>
    <?php the_post_video();?>
    <?php elseif (has_post_thumbnail( $post->ID ) ): ?>
    <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
    <?php endif; ?>
    <div class="overlayImg" style="background-image: url('<?php echo $image[0]; ?>')">

    Shows the video if there is one, otherwise the image as a background of a div.

    Only one question remains: “When using auto the video will be adjusted to fit it’s parent element while sticking to it’s ratio.”

    How do you get that to work with “the_post_video();” ? I set div.featured_video_plus to be 1000px wide and the div it loads into as well, player is still 560x3xx much appreciate the support, very nicely made plugin (I’m just very good at php etc, I’m a front-end guy)

    Plugin Author Alex

    (@ahoereth)

    Well maybe I should fix this to say “tries to fit it’s parent element” ?? It just uses a css width of 100% and then adjusts the height using some fancy JS.. Cannot ensure that it works everywhere. It does in the WordPress default themes I reccon.

    Thread Starter krill3

    (@krill3)

    Ah, used the nuclear option to get it to work (jQuery to check size of parent on load, switched iframe’s width to equal that, height to be 9/16 of height if that makes sense) less elegant but it works.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom post class on posts with featured videos?’ is closed to new replies.