php - How do I add the if and while loops to my html to make the ACF Flexible Content field work
Get the solution ↓↓↓I am trying to learn PHP to turn my static html sites to a dynamic WP Theme. I think my question should be easy for any WP developer, so I hope someone can help me.
Basically, I have my html index page with 3 layouts that I would like to use the flexible ACF field on, so that one can use these 3 layout as wanted on a page. This is just an example for me to practice on, not an actual site.
I know I have to use if and while loops for ACF Flexible Content, like:
<?php while ( have_rows('content') ) : the_row(); ?>
<?php if (get_row_layout() == 'team_members2'): ?>
<?php endif ?>
<?php endwhile; ?>
<?php endif; ?>
But I don't know where to insert these code snippets in my html, so that these 3 layouts would be created and can be 'called' in the backend/CMS, so that the user can add, remove and reorder the 3 layouts on a page.
Here is the basic html I am practicing on:
<div class="main-div">
<div class="layout-1">
<h1>Heading</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere. </p>
</div>
<div class="layout-2">
<div class="team-member-div">
<div class="team-image"></div>
<div class="team-name">
<h3 class="stretch-heading">Heading</h3>
</div>
</div>
</div>
<div class="layout-3">
<div class="image-1"></div>
</div>
</div>
Can someone show me how I would add the php snippets so that the 3 html layouts can be used in the CMS?
In ACF, I have set up a Flexible Field called 'content', so far I created one layout with the name: team_members2. In that layout I created 2 sub-fields: tm_image and tm_name
Of course I know I have to create 2 more layouts for the other html layouts, but haven't done that yet since I first want to be able to properly call the one layout
thanks so much for any help!
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: invalid argument supplied for foreach() laravel
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.