Support

Account

Home Forums Add-ons Flexible Content Field Displaying an Image gallery via a Flexible content field

Solved

Displaying an Image gallery via a Flexible content field

  • Hello, I am using your flexible content plugin to essentially create a page builder for my site to make data input easier. I am currently a bit stumped when it comes to formatting the code to display a Gallery in the Flexible content field, If you could help at all it would be appreciated, heres the template for my Flexible content page –

           
    	<div class="scp"> <!-- SCP start -->
    
    		<?php while(has_sub_field("page_builder")): ?>
    
    			<?php if(get_row_layout() == "heading"): ?> <!-- Heading Field -->
    
    				<div class ="scp-heading">
    					<?php the_sub_field("heading"); ?>
    				</div>
    
    			<?php elseif(get_row_layout() == "paragraph"): ?> <!-- Content Field -->
    
    				<div class="scp-text">
    					<?php the_sub_field("content"); ?>
    				</div>
    
    			<?php elseif(get_row_layout() == "image"): ?> <!-- Image Field -->
    
    				<div class="scp-image">
    					<img src="<?php the_sub_field("image"); ?>" />
    				</div>
    
    			<?php elseif(get_row_layout() == "gallery"): ?> <!-- Gallery Field -->
    			
    			<?php $images = get_field('gallery');
    				
    				if( $images ): ?> 
    				    <div id="slider" class="flexslider">
    				        <ul class="slides">
    				            <?php foreach( $images as $image ): ?>
    				                <li>
    				                    <img src="<?php echo $image['url']; ?>"/>
    				                </li>
    				            <?php endforeach; ?>
    				        </ul>
    				    </div>
    				 <?php endif; ?>
    				 
    			<?php endif; ?>
    
    		<?php endwhile; ?>
    
    	</div> <!-- SCP end -->
    
    

    Here’s the page for reference – http://vn.deckchairdesign.co.uk/about/about-me/
    All the other elements are inputted via flexible content fields and im attempting to display the gallery at the bottom of the page
    The site isn’t picking up any of the divs for the flexslider and I’m not sure why, thanks for reading, Harry.

  • Hi @harryadf

    I can see that you are using this line of code to get the gallery field values:

    
    <?php $images = get_field('gallery');
    

    Please remember that when you are loading a value from within a repeater field or flexible content field, you are loading a SUB field value, so please change your code to this:

    
    <?php $images = get_sub_field('gallery');
    

    Thanks
    E

  • Sweet, thanks @Elliot that worked a charm, I now have an issue with Flexslider not co-operating but I shan’t bother you with questions about another plugin!

    Thanks again, Solved!

    Harry.

    P.S. I accidentally set this to the topic solution when I meant to set Elliots answer as it, i’m happy to change it if you tell me how, sorry!

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

The topic ‘Displaying an Image gallery via a Flexible content field’ is closed to new replies.