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
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
Share Improve this question asked Jun 17, 2019 at 11:17 user170034user170034 31 bronze badge 1- The plugin is Media Hovers Wordpress Plugin. – user170034 Commented Jun 17, 2019 at 11:21
1 Answer
Reset to default 0I 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!