【问题标题】:Wordpress post thumbnail url is not working correctlyWordpress 帖子缩略图 url 无法正常工作
【发布时间】:2015-07-23 15:50:55
【问题描述】:

我在 wordpress 上构建的网站存在问题。

我正在尝试在我的博客页面中显示帖子缩略图,但它没有按预期工作...

这里是:

<?php $loop = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 9) );
                while ( $loop->have_posts() ) : $loop->the_post();
                $thumbnail = get_field( 'thumbnail' );
                $category = get_the_category();
                ?>
                <a href="<?php echo get_permalink(); ?>">
                            <section class="col-lg-4 col-md-6 col-sm-6" style=" background-image:url(<?php echo $thumbnail['url']; ?>);">
                                <div class="article-head">
                                    <h2><?php echo the_title(); ?><br><span><?php echo the_time(get_option('date_format')); ?></span></h2>
                                </div>
                            </section>
                        </a>
                <?php
                endwhile; 
                wp_reset_query(); ?>

所以在这里...我正在使用 ACF(高级自定义字段)插件来添加我称为“缩略图”的图像字段。

<?php echo $thumbnail['url']; ?>

这应该给我缩略图 url...但我得到的只是当前页面 url,即http://robeen.ca/blog/。我不明白为什么...

你们能帮帮我吗?

【问题讨论】:

  • get_field 不应返回数组,除非您使用中继器。转储$thumbnail,看看你得到了什么。

标签: php wordpress thumbnails


【解决方案1】:

get_field() 返回 Object(数据数组)、URL(字符串)或 ID(整数)。它可以在字段设置中更改。 var_dump()你的返回值,看看里面有什么。

See docs了解详情。

【讨论】:

  • 是的,如您所见,我使用 "$thumbnail['url'] 这意味着我正在从数组图片中获取 url...
猜你喜欢
  • 2011-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-04
  • 2013-07-17
  • 2015-07-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多