0

For my portfolio page, I want for certain items to display a video instead of just a still image for it's featured image. I have using a plugin to play the video on hover called upon by a shortcode. This I insert on each post with the help of AFC.

The custom field is called video_link and below I have tried to replace the featured image with the video by calling it via AFC if it's filled, I cannot get this to work.

<li id="post-<?php the_ID(); ?>" <?php post_class( $additional_classes ); ?>>
        <?php if( get_field( 'video_link' ) ) {
            get_field( 'video_link' );   
        } else {
            if( has_post_thumbnail( get_the_ID() {
                <?php get_the_image( array( 'size' => 'portfolio-thumb', 'width' => 600, 'height' => 400, 'before' => '<div class="post-thumb">', 'after' => '</div>' ) ); ?>
             }
        }
<h3><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'wp' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h3>

Any idea what is wrong. Any help is much appreciated.

Below is the website I'm trying to get this to work on:nordenson.nu

  • The plugin is Media Hovers Wordpress Plugin. – user170034 Jun 17 at 11:21
0

I think you have to pass post ID parameter in the get_field() if you get data using loop. so pass the in the get_field(). because currently it is trying to get data from current page field.

Try this if it works :

if( get_field( 'video_link', get_the_id() ) ) 
{
     get_field( 'video_link', get_the_id() ); 

} 
else 
{
    if( has_post_thumbnail( get_the_ID() 
    {
        get_the_image( array( 'size' => 'portfolio-thumb', 'width' => 600, 'height' => 400, 'before' => '<div class="post-thumb">', 'after' => '</div>' ) );
    }
}

So full loop content will be below:

<li id="post-<?php the_ID(); ?>" <?php post_class( $additional_classes ); ?> >
        <?php if( get_field( 'video_link',get_the_ID() ) ) {
            get_field( 'video_link',get_the_ID() );   
        } else {
            if( has_post_thumbnail( get_the_ID())) {
                get_the_image( array( 'size' => 'portfolio-thumb', 'width' => 600, 'height' => 400, 'before' => '<div class="post-thumb">', 'after' => '</div>' ) ); 
             }
        }
        ?>
<h3><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'wp' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h3>
</li>

let me know if it works.

Thank you!

  • Hi Chetan and thanks for the very quick reply! Unfortunately, this doesn't solve it. The if( get_field( 'video_link', get_the_id() ) ) gets caught inside the post_class. You can see it live with this error on the page right now. So now I get neither video nor images. Do you have any idea of what to change to get it out of there? – user170034 Jun 17 at 11:38
  • i have updated with full code. please try to implement in proper way. this should be works. let me no if it will works – Chetan Vaghela Jun 17 at 11:50
  • Hi Chetan, Thank you once again! Your update got me a bit closer now however it seems to just directly call the thumbnail even if the 'video_link" field if filled. – user170034 Jun 17 at 11:58
  • I can see there is two errors in console. these error cause issue rendering video. try to solve these error then check this should works properly. – Chetan Vaghela Jun 17 at 12:01
  • Chetan, I resolved these two issues that came of an earlier attempt at making this using another plugin. But still can't get AFC to render the information now. – user170034 Jun 17 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.