タクソノミー=投稿カテゴリの画像用にACFフィールドを作成しました。これらの画像と作品を出力するループを書きました。参考として記事の最後に追記しました。
ここで画像サイズを選択したいので、 wp_get_attachment_image を使用するより高度な方法を試しました (ここで概説: http://www.advancedcustomfields.com/resources/field-types/image/ ):
$attachment_id = get_field('field_name');
$size = "full"; // (thumbnail, medium, large, full or custom size)
$image = wp_get_attachment_image_src( $attachment_id, $size );
だから私は上記を
$attachment_id = get_field('category_image', $taxonomy . '_' . $term->term_id);
$size = "full"; // (thumbnail, medium, large, full or custom size)
$image = wp_get_attachment_image_src( $attachment_id, $size );
そして画像に追加されました
echo $image[0]
しかし、これは bool(false) を出力し、機能しません。何か案は?
これは、ループ内で画像の URL を正しく出力するコードです。
<div class="category-image">
<?php
$taxonomy = 'category';
$queried_term = get_term_by( 'slug', get_query_var($taxonomy), 0 );
$terms = get_terms($taxonomy);
if ($terms) {
echo '<ul>';
foreach($terms as $term) {
// ACF
$image = get_field('category_image', $taxonomy . '_' . $term->term_id);
// TEST to see field
// var_dump( $image );
if( get_field('category_image', $taxonomy . '_' . $term->term_id)):
?> <li><a href="<?php echo get_term_link($term->slug, $taxonomy) ?>"><img src="<?php echo $image['url'] ; ?>" alt="" /><h4><?php echo $term->name ?></h4></a></li>
<?php endif; } ?>
</ul> </div>