Home › Forums › General Issues › ACF Table Loop W/ Alternating Row Color
I’m having trouble finalizing the specifications section of each product on my site. I’m successfully pulling in all of the field groups that I need in the table shown on this page just below the product image. https://staging-casterconcepts.kinsta.cloud/product/4×2-t-r-95-polyurethane-caster-wheel-3/
Where I’m having issues is finding a way to omit the PRJ Link field without it breaking my alternating cell color styling. I can’t seem to find any references where I can pull all and only the fields that have data and omit any that I would like, and for the table to keep an alternating row color. This is how I’m pulling in the data, any links to examples or suggestions would be greatly appreciated.
<!– Product Specs –>
<div class=”row”>
<h2 class=”prod-bb”><?php esc_html_e( ‘Specifications’ ); ?></h2>
</div>
<div class=”row”>
<?php
//$id = $product->get_id();
$fields = get_field_objects(); if( $fields ): ?>
<?php foreach( $fields as $field ): ?>
<?php if( $field[‘value’] ): ?>
<div class=”col-xl-6 spec-col”>
<?php echo $field[‘label’]; ?>: <?php echo $field[‘value’]; echo $field[‘append’]; ?>
</div>
<?php endif; ?>
<?php endforeach; ?>
<div class=”col-xl-6 spec-col”><?php esc_html_e( ‘SKU:’ ); ?> <?php echo $product->get_sku(); ?></div>
<div class=”col-xl-6 spec-col”><span class=”<?php if ( $product->get_weight() == ” ) { echo ‘d-none’; } ?>”><?php esc_html_e( ‘Caster Weight:’ ); ?> <?php echo $product->get_weight(); ?> <?php esc_html_e( ‘lbs’ ); ?></span></div>
<?php endif; ?>
</div><!– #end product specs –>
For alternating rows, should the row tag not be in the loop and the alternative class be applied to that?
That way, you could also wrap the if( $field[‘value’] ): around the row, so shouldn’t break if a row returns empty.
You must be logged in to reply to this topic.
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.