我正在 wordpress 中的网站上工作,我正在尝试从帖子的高级自定义字段中获取缩略图:

<?php while ( have_posts() ) : the_post(); ?>
    <h1><?php the_field('custom_title'); ?></h1>
    <img src="<?php the_field('thumbnail'); ?>" alt="" />
    <p><?php the_content(); ?></p>
<?php endwhile; // end of the loop. ?>

问题在于,当我加载网站时,图像获取的 url 如下所示:
<img src="5, , item_alt2, , , http://portfolio.local/wp-content/uploads/2012/09/item_alt2.jpg, Array">

所以,据我所知,它正在工作的插件寻找图像,但它加载了一条奇怪的路径,所以它显示为“损坏的”图像。

我在做什么错?
 5, , item_alt2, , , http://portfolio.local/wp-content/uploads/2012/09/item_alt2.jpg, ArrayNULL

最佳答案

查看高级自定义字段的文档;

http://www.advancedcustomfields.com/docs/field-types/image/

根据底部的示例,您将自定义字段的值作为对象返回;

Array
(
[id] => 540
[alt] => A Movie
[title] => Movie Poster: UP
[caption] => sweet image
[description] => a man and a baloon
[url] => http://localhost:8888/acf/wp-content/uploads/2012/05/up.jpg
[sizes] => Array
    (
        [thumbnail] => http://localhost:8888/acf/wp-content/uploads/2012/05/up-150x150.jpg
        [medium] => http://localhost:8888/acf/wp-content/uploads/2012/05/up-300x119.jpg
        [large] => http://localhost:8888/acf/wp-content/uploads/2012/05/up.jpg
        [post-thumbnail] => http://localhost:8888/acf/wp-content/uploads/2012/05/up.jpg
        [large-feature] => http://localhost:8888/acf/wp-content/uploads/2012/05/up.jpg
        [small-feature] => http://localhost:8888/acf/wp-content/uploads/2012/05/up-500x199.jpg
    )

)

关于php - 高级自定义字段缩略图 - wordpress,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12333169/

10-11 03:13