Support

Account

Home Forums Add-ons Repeater Field Add title from repeater field to image title

Helping

Add title from repeater field to image title

    • ttmt_101

    • September 27, 2013 at 6:51 am

    Hi

    I have a Repeater field called Images that has the sub fields ‘image’ and ‘title’

    I’m creating a li list with the images. I would like to add the image title from the title sub field to the image. How do I add the title sub field.

    		<section class="gallery">
    			
    			<?php
    			
    			$rows = get_field('images');
    			
    			if($rows){
    				
    				echo '<ul>';
    
    				foreach($rows as $row){
    
    					$attachment_id = $row['image'];
    					$thumb = "thumbnail";
    					$large = "large";
    					$thumb_img = wp_get_attachment_image_src( $attachment_id, $thumb );
    					$large_img = wp_get_attachment_image_src( $attachment_id, $large );
    					
    					echo '
    					<li>
    						<a href="'.$large_img[0].'">
    							<img class="alignnone size-full wp-image-100 img" src="'.$thumb_img[0].'" alt="img" width="'.$thumb_img[1].'"	height="'.$thumb_img[2].'" title="'.the_sub_field('title').'"/>
    						</a>
    					</li>';
    				}
    
    				echo '</ul>';
    			}
    			?>
    			
    		</section>
    
    • Elliot

    • September 30, 2013 at 3:13 pm

    Hi @ttmt_101

    Because you are using abasic PHP aproach to looping through your repeater rows, you need to use the code $row['title'] to load the relative title value. Using the_sub_field will not work in this situation.

    Thanks
    E

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.