画像ID
<?php if( get_field('images')): ?><?php
$image = get_field('images');$size = 'thumbnail';
if( $image ) {echo wp_get_attachment_image( $image, $size );}?>
<?php else: ?>
<img src="代替画像のURL">
<?php endif;?>
画像URL
<?php if( get_field('images')): ?>
<img src="<?php $image = the_field('images');$size = 'thumbnail';
if( $image ) {echo wp_get_attachment_image( $image, $size );}?>">
<?php else: ?>
<img src="代替画像のURL">
<?php endif;?>
画像オブジェクト
<?php
$image = get_field('img');
if( !empty($image) ):
$url = $image['url'];
$title = $image['title'];
$alt = $image['alt'];
$size = 'thumbnail';
$thumb = $image['sizes'][ $size ];
$width = $image['sizes'][ $size . '-width' ];
$height = $image['sizes'][ $size . '-height' ];
<a href="<?php echo $url; ?>" title="<?php echo $title; ?>">
<img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>">
</a>
<?php endif; ?>
繰り返しフィールド(repeat)に入れた画像画像URL
<?php if( get_sub_field('images')): ?>
<img src="<?php $image = the_sub_field('images');$size = 'thumbnail';
if( $image ) {echo wp_get_attachment_image( $image, $size );}?>">
<?php else: ?>
<img src="代替画像のURL">
<?php endif;?>
コメント