Home › Forums › Add-ons › Flexible Content Field › Write CSS with PHP and Flexible Content › Reply To: Write CSS with PHP and Flexible Content
I’m sorry if this isn’t answering your question directly, but for things like this, wouldn’t it be simpler to just assign a class to the layout and then style that class appropriately?
For instance:
<?php if( have_rows('pagebuilder') ): ?>
<?php while( have_rows('pagebuilder') ): the_row(); ?>
<?php if( get_row_layout() == 'page_mainteaser' ): ?>
/* Site-Mainteaser */
// I made these attributes multiline to read easier on these forums
<div id="mainteaser"
style="background-image: url('<?php the_sub_field('background'); ?>')"
class="headline-<?php the_sub_field('color_headline'); ?>
text-<?php the_sub_field('color_text'); ?>"
>
<!-- Layout content here... -->
</div>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
Then in your stylesheet add corresponding styles like:
.headline-red h1 { color: red }
.headline-blue h1 { color: blue }
.headline-green h1 { color: green }
.text-black p { color: black}
.text-white p { color: white }
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.