Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何获取WordPress图像缩略图链接?(非特色图片)_Php_Wordpress_Gallery - Fatal编程技术网

Php 如何获取WordPress图像缩略图链接?(非特色图片)

Php 如何获取WordPress图像缩略图链接?(非特色图片),php,wordpress,gallery,Php,Wordpress,Gallery,我正在尝试用WordPress高级自定义字段和repeater字段插件构建一个简单的图库。我需要显示一个缩略图,你点击放大主图像(我使用的是Fancybox)。有人知道WordPress自动生成的图像缩略图的链接是否可能吗 我可以获得主图像链接: /wp content/uploads/2014/12/slide1.jpg 但需要获得此图像链接: /wp content/uploads/2014/12/slide1-150x150.jpg 这是我的密码: <?php if(get_fiel

我正在尝试用WordPress高级自定义字段和repeater字段插件构建一个简单的图库。我需要显示一个缩略图,你点击放大主图像(我使用的是Fancybox)。有人知道WordPress自动生成的图像缩略图的链接是否可能吗

我可以获得主图像链接: /wp content/uploads/2014/12/slide1.jpg

但需要获得此图像链接: /wp content/uploads/2014/12/slide1-150x150.jpg

这是我的密码:

<?php if(get_field('gallery')): ?>
    <ul>
        <?php while(has_sub_field('gallery')): ?>
            <a class="fancybox" href="<?php the_sub_field('image'); ?>" data-fancybox-group="gallery" title="Lorem ipsum dolor sit amet"><img src="<?php the_sub_field('image'); ?>" alt="" width="200px;" height="auto"/></a>
        <?php endwhile; ?>
        <?php while(has_sub_field('video_link')): ?>
            <a class="fancybox-media" href="<?php the_sub_field('video_link_snippet'); ?>"><img src="<?php the_sub_field('video_image'); ?>"/></a>
        <?php endwhile; ?>
    </ul>
<?php endif; ?>


使用高级自定义字段和Wordpress,您完全可以做到这一点。为此,进入自定义字段并更改子字段“image”,使其返回图像对象而不是图像URL

此字段返回对象后,请尝试使用var_转储字段以查看URL选项:

var_dump(the_sub_field('image'));
这将显示系统中启用的不同缩略图大小,并允许您轻松获取所需的缩略图。一个可能的例子:

// Get image object with all sizes...
$image = the_sub_field('image');
$size = 'thumbnail';

// Get URL from sizes based on our $size var
$url = $image['sizes'][$size];

// Now we have the thumbnail URL
echo $url;

如果遇到问题,请告诉我!有关更多文档和更多选项,请尝试

嘿!请让我知道,如果你需要任何额外的帮助这个问题。如果这个问题解决了,请考虑选择答案。谢谢你的帮助!我尝试了var_转储该字段,但它没有显示任何“大小”=>的结果。我在functions.php文件中创建了各种图像大小,它应该显示这些吗?嘿,我看到你在这里发布了var_转储文件,它确实说了“大小”。你能重新发布var_dump结果吗?我将提供一个如何从中获取特定缩略图的示例?
array 0=>array'image'=>array'id'=>int 54'alt'=>string''(length=0)'title'=>string'slide1'(length=6)'caption'=>string''(length=0)'description'=>string'(长度=0)'mime_type'=>string'image/jpeg'(长度=10)'url'=>string'http://localhost/wp-content/uploads/2014/12/slide1.jpg'(长度=54)“宽度”=>int1000“高度”=>int630“大小”=>array…
我用这段代码来概括变量转储:
太好了,我已经尝试了这段代码,现在它正在工作。非常感谢您的帮助!!!:-)