【问题标题】:Advanced Custom Field (ACF) not displaying thumbnail高级自定义字段 (ACF) 不显示缩略图
【发布时间】:2013-07-23 05:34:47
【问题描述】:

我在页面上有一个图片库,我正在使用高级自定义字段来提取该图片的缩略图和更大版本。现在,我将它设置为两个单独的字段,因此用户必须上传两个单独的图像(缩略图和完整尺寸)。我正在尝试进行设置,因此用户只需上传一张图片,但是当我按照http://www.advancedcustomfields.com/resources/field-types/image/ 上的示例进行操作时,我的缩略图不起作用,但完整的图片仍然有效。这是我一直在使用的代码:

<?php query_posts(array(
                'post_type' => 'gallery_images',
                'posts_per_page' => 20,
)); ?>

<?php while (have_posts()) : the_post(); $gallery_images; 

                $attachment_id = get_field('gallery_full');
                $size = "thumbnail"; // (thumbnail, medium, large, full or custom size)
                $image = wp_get_attachment_image_src( $attachment_id, $size );

?>
      <div class="gallery_image_wrap"><a rel="shadowbox[galpage]" href="<?php the_field('gallery_full'); ?>"><img src="<?php echo $image[0]; ?>" /></a></div>                    


<?php endwhile; ?> 
<?php wp_reset_query(); ?>

这是它返回的示例:

<div class="gallery_image_wrap">
<a href="http://example.com/photo.jpg" rel="shadowbox[galpage]">
<img src=" ">
</a>
</div>

我做错了什么? (另外,我尝试上传一张新图片,看看是否有解决方案,但我仍然遇到了同样的问题。)

【问题讨论】:

    标签: image wordpress thumbnails custom-fields options-menu


    【解决方案1】:

    wp_get_attachment_image_src 将返回本地文件系统中不存在的缩略图的原始图像。此函数返回一个布尔值,如果正在使用缩略图,则返回 TRUE,如果正在使用原始缩略图,则返回 FALSE。

    您可以通过以下方式查看:

    <?php while (have_posts()) : the_post(); $gallery_images; 
    
                    $attachment_id = get_field('gallery_full');
                    $size = "thumbnail"; // (thumbnail, medium, large, full or custom size)
                    $image = wp_get_attachment_image_src( $attachment_id, $size );
                    if(!$image[3]) { echo "Thumbnail not available"; }
    ?>
    

    上面的代码可能对您的问题没有多大帮助,但它会让您更好地了解逻辑中断的位置。

    如果确实发生了这种情况,您应该根据一些文档查看 PHP 的内存限制。这可以通过在 .htaccess 中添加以下行来解决:

    php_value memory_limit 128M
    

    【讨论】:

    • 这样做之后,Wordpress 似乎没有生成缩略图。我尝试将内存限制添加到 .htaccess 文件中,但没有成功……还有其他建议吗?
    猜你喜欢
    • 1970-01-01
    • 2012-09-02
    • 1970-01-01
    • 2016-11-13
    • 2018-04-15
    • 2018-11-15
    • 2020-09-29
    • 1970-01-01
    • 2015-11-04
    相关资源
    最近更新 更多