【发布时间】: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