【问题标题】:how to hover featured img in wordpress with ACF如何使用 ACF 在 wordpress 中悬停特色图像
【发布时间】:2021-03-20 18:32:00
【问题描述】:

我有代码

<div class=""/> <a href="<?php echo get_permalink( $post->ID ); ?>"> <?php
        if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
            the_post_thumbnail( 'full', array( 'class'  => 'img-fluid d-block mx-auto' ) ); // show featured image
        }

我应该添加什么来制作特色 img 悬停。悬停img应该从ACF字段“imghover”获取

【问题讨论】:

    标签: jquery wordpress hover advanced-custom-fields


    【解决方案1】:

    将此代码放入您的文件中。

    <div class=""/> <a href="<?php echo get_permalink( $post->ID ); ?>"> <?php the_field('imghover');?></div>
        
    

    【讨论】:

    • 我认为它只会在代码中添加 hover img。我想要功能 img,当我将鼠标放在 img 上后,我会看到悬停
    • @stecu 是从 ACF 获取你的“imghover”值
    • 对于悬停(mounce on img)你需要添加一些css代码来实现悬停效果...
    • 是的,但我想要 onmouseover 和 onmouseout 函数&lt;div class=""/&gt; &lt;a href="&lt;?php echo get_permalink( $post-&gt;ID ); ?&gt;"&gt; &lt;img src="&lt;?php echo get_the_post_thumbnail($the_query-&gt;post-&gt;ID); ?&gt;" class="img-fluid d-block mx-auto" onmouseover="this.src='&lt;?php echo esc_url($hoverimage['url']); ?&gt;'" onmouseout="this.src='&lt;?php echo get_the_post_thumbnail($the_query-&gt;post-&gt;ID);?&gt;'" /&gt; &lt;/a&gt;&lt;/div&gt;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-18
    • 1970-01-01
    • 2019-01-21
    • 2015-04-05
    • 2016-12-11
    • 2020-06-04
    相关资源
    最近更新 更多