You will need to set the return value of the image field to ‘object’, currently it looks set to ‘URL’.
Then you can do something like this:
<?php while ( have_posts() ) : the_post(); ?>
<?php if( get_field('projectafbeelding') ): ?>
<?php while( has_sub_field('projectafbeelding') ):
$image = get_sub_field('afbeelding');
?>
<li style="background-image: url('<?php echo $image['url'];?>');">
<?php echo $image['title'];?>
</li>
<?php endwhile; ?>
<?php endif; ?>
<?php endwhile; ?>
If the field is set to ‘URL’ then just use:
<img src="<?php echo $image; ?>" alt="" />
or:
<img src="<?php the_sub_field('slider_images'); ?>" alt="" />
Your original code:
<img src="<?php echo $image['url']; ?>" alt="" />
refers to the ‘image object’ which your not using.
Use ‘get_field();’
<?php
$x1 = get_field('eye');
$x2 = get_field('movement');
$x3 = get_field('verbal');
$x4 = $x1+$x2+$x3 ;
echo "</br> Value is $x4" ;
?>
Count and Break.
<?php
$rows = get_field('career_grid');
if($rows){
shuffle( $rows )
$i = 0;
foreach($rows as $row){
$image = wp_get_attachment_image_src( $row['image'], 'full');
?>
<a href="<?php echo $row['link']; ?>">
<img src="<?php echo $image[0]; ?>" alt="<?php echo $image['alt']; ?>" />
</a>
<?php
if (++$i == 2) break;
}
}
?>
This might help.
<?php $allow[] = get_sub_field('ip_address'); ?>
Something like this should get you looking in the right direction.
<?php if ( have_posts() ) : while ( $fullbanner->have_posts() ) : $fullbanner->the_post(); ?>
<?php $banners = get_field(‘home_banner_01_selection’); ?>
<?php if( $banners ): ?>
<?php shuffle($banners); ?>
<?php foreach(array_slice($banners, 0, 1) as $banner ): ?>
<?php the_field( 'home_headline', $banner->ID ); ?>
<?php endforeach; ?>
<?php endif; ?>
<?php endif; ?>
Use a counter and break out the loop when you get to ‘3’.
<?php
if( have_rows('latest_offers', 'options') ):
$i = 0;
while ( have_rows('latest_offers', 'options') ) : the_row(); ?>
<?php $i++; ?>
<?php if( $i > 3 ):
<?php break; ?>
<?php endif; ?>
<a href="<?php the_sub_field('page_link'); ?>" class="hot">
<div class="img"><img src="<?php the_sub_field('brand_logo'); ?>" alt=""></div>
<div class="text">
<div class="smlltxt"><?php the_sub_field('heading'); ?></div>
<div class="num"><?php the_sub_field('price'); ?></div>
<div class="txt"><?php the_sub_field('description'); ?></div>
</div>
<img src="<?php echo get_template_directory_uri(); ?>/img/hot.png" alt="" class="hot_img">
</a>
<?php endwhile;
else :
endif;
?>
Something like this.
<?php if( have_rows('repeater_field_name') ): ?>
<?php while ( have_rows('repeater_field_name') ) : the_row(); ?>
<?php
$attachment_id = get_sub_field('file_upload');
$url = wp_get_attachment_url( $attachment_id );
$title = get_the_title( $attachment_id );
// part where to get the filesize
$filesize = filesize( get_attached_file( $attachment_id ) );
$filesize = size_format($filesize, 2);
?>
<!-- display a sub field value -->
<div class="item-upload">
<?php the_sub_field('file_upload'); ?> (<?php echo $filesize; ?>)
</div>
<?php endwhile; else : ?>
<?php endif; ?>
Treat the repeater field as an array, you can count the number of values.
<?php if( have_rows('services_repeater', $services) ): ?>
<?php $rowCount = count( get_field('services_repeater', $services) ); //GET THE COUNT ?>
<?php $i = 1; ?>
<?php while( have_rows('services_repeater', $services) ): the_row(); ?>
<?php // vars
$service = get_sub_field('service');
$description = get_sub_field('description');
?>
<span class="hint--bottom" data-hint="<?php echo $description; ?>"><?php echo $service; ?></span>
<?php if($i < $rowCount): ?>
<div id="separator"> / </div>
<?php endif; ?>
<?php $i++; ?>
<?php endwhile; ?>
<?php endif; ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.