WordPress.org

Ready to get started?Download WordPress

Forums

Featured Video Plus
[resolved] Custom post class on posts with featured videos? (5 posts)

  1. KriLL3
    Member
    Posted 9 months ago #

    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.

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

  2. Alexander Hoereth
    Member
    Plugin Author

    Posted 9 months ago #

    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.

  3. KriLL3
    Member
    Posted 9 months ago #

    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)

  4. Alexander Hoereth
    Member
    Plugin Author

    Posted 9 months ago #

    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.

  5. KriLL3
    Member
    Posted 9 months ago #

    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.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.