【问题标题】:fancybox not loading images in WordPressfancybox 没有在 WordPress 中加载图像
【发布时间】:2014-08-27 08:27:49
【问题描述】:

我正在将我的 html 模板转换为 WordPress。 Fancybox 在我的 html 版本中运行良好,但在 wordpress 中却不行。

在 html 版本中,fancybox 代码为:

<a href="images/p3.jpg" class="project-img fancybox"></a>

现在在 WP 版本中:

<a href="<?php the_post_thumbnail(); ?>" class="project-img fancybox"></a>

&jQuery:

$(".fancybox").fancybox({

        padding     : 0,
        margin      : 100,
        openEffect  : 'elastic',
        closeEffect : 'elastic',
        openSpeed   : 400,
        closeSpeed  : 400,

        helpers : {
            overlay : {
                css : {
                    'background' : 'rgba(0, 0, 0, 0.75)'
                }
            }
        }
    });

但它对我不起作用,当我将图像悬停时,它会返回:

class="project-img fancybox">

我不是专业人士,所以找不到任何解决方案。

【问题讨论】:

    标签: jquery html wordpress fancybox


    【解决方案1】:

    使用函数get_the_post_thumbnail

    您不能将 the_post_thumbnail 传递到 href 标记中。

    【讨论】:

    • 但问题是我在该部分有 4 个帖子,所有帖子都是由循环动态生成的。如果我使用 get_the_post_thumbnail(),我必须使用参数 ($post_id) & 我不知道如何使它动态
    【解决方案2】:

    您在href 属性中使用了不正确的函数。它显示当前帖子的特色图像(以前称为帖子缩略图),如该帖子的编辑屏幕中设置的那样。该标签必须在 The Loop 中使用。

    改用get_the_post_thumbnail()

    &lt;a href="&lt;?php get_the_post_thumbnail( $post_id, $size, $attr ); ?&gt;" class="project-img fancybox"&gt;&lt;/a&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多