问题
i would like to add a class to my html (.complete) with php:
if( get_field('to-do-repeater') )
{
Add (complete) class to <div class="to-do to-do-wrap"> should be <div class="to-do to-do-wrap complete">
}
else
{
Do nothing
}
回答1:
Try this code :
<div class="to-do to-do-wrap<?php echo get_field('to-do-repeater') ? ' complete' : '' ?>"></div>
回答2:
<?php
echo "<div class=\"to-do to-do-wrap ";
if(get_field('to-do-repeater'))
{
echo "complete";
}
echo " \"></div>";
?>
来源:https://stackoverflow.com/questions/11852425/php-add-class-to-html-div