• Resolved daisy-d

    (@daisy-d)


    Hi,

    I’m using the Advanced Custom Fields plugin with the Repeater add-on. (http://www.advancedcustomfields.com)

    I have a repeater field called portfolio_images with two sub fields – image and portfolio_link.

    Some images will be linked and others not so I only want the link to appear if the field has been completed otherwise I just want the image to show.

    This is the code I am using at the moment:

    <?php if( have_rows('portfolio_images') ): ?>
    <?php while( have_rows('portfolio_images') ): the_row(); ?>
    <?php
         $portfolio_link = get_sub_field('portfolio_link');
         if ($portfolio_link == '') {
              echo '<img src="' . the_sub_field('image') . '" /><br />';
         }
         else {
              echo '<a href="' . the_sub_field('portfolio_link') . '"><img src="' . the_sub_field('image') . '" />' . '</a><br />';
         }
    ?>
    <?php endwhile; ?>
    <?php endif; ?>

    It outputs all of the values but just not within the html i.e.

    http://www.bob.co.ukhttp://dd-dev.co.uk/bob/wp-content/uploads/2014/11/ifp-portfolio-1.png<a href=""><img src="" /></a>                                    
    
    http://dd-dev.co.uk/bob/wp-content/uploads/2014/11/ifp-portfolio-2.png<img src="" />

    Can anyone help me at all?

    Thanks

Viewing 1 replies (of 1 total)
  • Thread Starter daisy-d

    (@daisy-d)

    Managed to find the solution so if anyone else comes across something similar this fixed it:

    <?php if( have_rows('portfolio_images') ): ?>
         <?php while( have_rows('portfolio_images') ): the_row(); 
    
              $image = get_sub_field('image');
              $link = get_sub_field('portfolio_link');
    
         ?>
         <?php if( $link ): ?>
              <a href="<?php echo $link; ?>">
         <?php endif; ?>
    
         <img src="<?php echo $image; ?>" />
    
         <?php if( $link ): ?>
              </a>
         <?php endif; ?>                                
    
         <?php endwhile; ?>
    <?php endif; ?>
Viewing 1 replies (of 1 total)

The topic ‘Conditional Statement (Advanced Custom Fields)’ is closed to new replies.