I got some stuff working after playing around for awhile. First, here’s my current test setup—the flexible content has two different image uploads right now, one that spits out an image only, and another that spits out an image wrapped in some HTML that looks like a browser window.
And here’s the code I’m using to have it spit it all out:
<?php if( have_rows('project_content') ): ?>
<?php while( have_rows('project_content') ): the_row(); ?>
<?php // Normal Image Content Block
if( get_row_layout() == 'content_image' ): ?>
<?php // Vars
$contentImage = get_sub_field('image');
echo '<figure><img src="'. $contentImage['url'] .'" alt="'. $contentImage['alt'] .'" /></figure>'
?>
<?php endif; ?>
<?php // Browser Image Content Block
if( get_row_layout() == 'content_image_browser' ): ?>
<?php // Vars
$browserImage = get_sub_field('image_browser');
$browserLabel = get_sub_field('image_browser_label');
echo '<figure class="browser"><div><span></span><span></span><span></span></div><img src="'. $browserImage['url'] .'" alt="'. $browserImage['alt'] .'" /><figcaption>'. $browserLabel . '</figcaption></figure>'
?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
Hope that helps you out! It did the trick for me. Now I’m just going to be following that same template and adding other content block types.
I am in the same boat here. I just upgraded to Pro and am trying to use Flexible Content for the first time and not having any luck. Eliot, is there anyway you can post the exact code you used from the demo video? I think that would lend a lot of help with syntax and how to query everything properly.
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.