最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

customization - Replace featured image when shortcode is present

programmeradmin1浏览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

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
Add a comment  | 

1 Answer 1

Reset to default 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!

发布评论

评论列表(0)

  1. 暂无评论