【发布时间】:2016-05-18 21:59:54
【问题描述】:
我在 wordpress 网站上使用 acf 插件。我正在使用带有显示在博客文章上的图像子字段的转发器字段。我的目标是只获取并显示博客文章中的第一张和第二张图片,以显示在主页上。
我尝试使用 acf 站点文档中的此代码,但无济于事,该代码无法正常工作。有人可以知道这个问题吗?
<?php while ($the_query -> have_posts()) : $the_query ->
the_post();
$postqID = get_the_ID();
?>
<?php
$rows = get_field('post_images', $postqID ); // get all the rows
$first_row = $rows[0]; // get the first row
$first_row_image = $first_row['post_image' ]; // get the sub field value
// Note
// $first_row_image = 123 (image ID)
$image = wp_get_attachment_image_src( $first_row_image, 'full' );
// url = $image[0];
// width = $image[1];
// height = $image[2];
?>
<img src="<?php echo $image[0]; ?>" />
【问题讨论】:
标签: php wordpress repeater advanced-custom-fields