我有 wp 网站,其页面以网格格式显示产品,如投资组合。我的主题使用标准 index.php 页面进行循环,并使用函数文件根据帖子类型和设置输出实际内容。我想将鼠标悬停在我的投资组合网格布局中的特色图片上,以显示我放入名为“hover-thumb”的自定义字段中的另一张图片。我在网上搜索了以下内容,得出的结论是最好的方法,但是当我查看输出的源代码时,我无法弄清楚为什么悬停图像源为空。如果仅填充图像,悬停效果似乎就可以工作。我不是程序员,所以这对我来说非常复杂。我希望那里有人能说清楚。我通过在下面的 et_overlay span 标记中添加 php 来修改下面的代码(在函数文件中)...src=""是空的 http://eyemajic.staging.wpengine.com/matte-finish/ 感谢您提出更好的建议,我很想在我自己的子主题的函数文件中使用它,但不知道如何我可以添加我的修改或者我需要在我的函数文件中包含多少原始代码。
<?php
$thumb = '';
$width = 'on' === $fullwidth ? 1080 : 400;
$width = (int) apply_filters( 'et_pb_portfolio_image_width', $width );
$height = 'on' === $fullwidth ? 9999 : 284;
$height = (int) apply_filters( 'et_pb_portfolio_image_height', $height );
$classtext = 'on' === $fullwidth ? 'et_pb_post_main_image' : '';
$titletext = get_the_title();
$thumbnail = get_thumbnail( $width, $height, $classtext, $titletext, $titletext, false, 'Blogimage' );
$thumb = $thumbnail["thumb"];
if ( '' !== $thumb ) : ?>
<a href="<?php the_permalink(); ?>">
<?php if ( 'on' !== $fullwidth ) : ?>
<span class="et_portfolio_image">
<?php endif; ?>
<?php print_thumbnail( $thumb, $thumbnail["use_timthumb"], $titletext, $width, $height ); ?>
<?php if ( 'on' !== $fullwidth ) : ?>
<span class="et_overlay"><?php $hover_image = get_post_meta($post->ID, 'hover-thumb', true); ?>
<img class="hover-img" src="<?php echo $hover_image; ?>" /> </span>
</span>
<?php endif; ?>
</a>