Home › Forums › Add-ons › Repeater Field › Link image repeater field
Adding external link to image in repeater field
<?php
$rows = get_field('slider');
$row_count = count($rows);
$max = ($row_count - 1);
$numbers = range (0, $max);
shuffle($numbers);
$random_1 = $numbers[0];
$random_2 = $numbers[1];
$random_3 = $numbers[2];
$random_4 = $numbers[3];
$random_5 = $numbers[4];
$random_6 = $numbers[5];
$random_7 = $numbers[6];
$imagefield_1 = $rows[$random_1]['logo'];
$imagefield_2 = $rows[$random_2]['logo'];
$imagefield_3 = $rows[$random_3]['logo'];
$imagefield_4 = $rows[$random_4]['logo'];
$imagefield_5 = $rows[$random_5]['logo'];
$imagefield_6 = $rows[$random_6]['logo'];
$textfield_1 = $rows[$random_1]['link'];
$image1 = wp_get_attachment_image_src($imagefield_1, 'logo');
$image2 = wp_get_attachment_image_src($imagefield_2, 'logo');
$image3 = wp_get_attachment_image_src($imagefield_3, 'logo');
$image4 = wp_get_attachment_image_src($imagefield_4, 'logo');
$image5 = wp_get_attachment_image_src($imagefield_5, 'logo');
$image6 = wp_get_attachment_image_src($imagefield_6, 'logo');
?>
<div class="image first">
<a href="<?php echo $textfield_1['link']; ?>"><img src="<?php echo $image1[0]; ?>" alt="<?php get_the_title($imagefield_1) ?>" /></a>
</div>
<div class="image second">
<a href="<?php echo $link; ?>"><img src="<?php echo $image2[0]; ?>" alt="<?php get_the_title($imagefield_2) ?>" /></a>
</div>
<div class="image third">
<a href="<?php echo $link; ?>"><img src="<?php echo $image3[0]; ?>" alt="<?php get_the_title($imagefield_3) ?>" /></a>
</div>
<div class="image fourth">
<a href="<?php echo $link; ?>"><img src="<?php echo $image4[0]; ?>" alt="<?php get_the_title($imagefield_4) ?>" /></a>
</div>
<div class="image fifth">
<a href="<?php echo $link; ?>"><img src="<?php echo $image5[0]; ?>" alt="<?php get_the_title($imagefield_5) ?>" /></a>
</div>
<div class="image sixth">
<a href="<?php echo $link; ?>"> <img src="<?php echo $image6[0]; ?>" alt="<?php get_the_title($imagefield_6) ?>" /></a>
</div>
<?php endwhile; // end of the loop. ?>
It just links to the home page. Any suggestions? I have a repeater sub field called link.
Hi @krislynn
I think the issue is you are assuming the wrong variables.
You have saved the link data as:
$textfield_1 = $rows[$random_1]['link'];
You should echo the link like this:
<?php echo $textfield_1; ?>
not,
<?php echo $textfield_1['link']; ?>
Please debug your variables before posting back a reply.
Thanks
Elliot
The topic ‘Link image repeater field’ is closed to new replies.
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.