Ecommerce Shopify WordPress Discussion

Create a loop of Multiple li tag where html code is same but the value is different

In my custom template of WordPress theme i have around 20+ li tag element where the html code is same and value is different. and i am creating separate condition for each element. Is it possible to set a loop of this code, so that i should not create every li tag a separate condition and less my html code. <?php $user_birthday = get_post_meta(get_the_ID(), 'user_birthday', true); ?> <?php if(!empty($user_birthday)) { ?> <li> <span class="min-w-[100px] mr-2 inline-block font-bold" >Birthday:</span ><span class="text-slate-500"><?php echo $user_birthday; ?></span> </li> <?php } ?> <?php $user_age = get_post_meta(get_the_ID(), 'user_age', true); if(!empty($user_age)) { ?> <li> <span class="min-w-[100px] mr-2 inline-block font-bold" >Age:</span ><span class="text-slate-500"><?php echo $user_age; ?></span> </li> <?php } ?>
You can loop the content <?php $user_birthday = get_post_meta(get_the_ID(), 'user_birthday', true); $user_age = get_post_meta(get_the_ID(), 'user_age', true); $items = [ 'Birthday' => $user_birthday, 'Age' => $user_age ]; foreach ($items as $label => $value) { if (!empty($value)) echo "<li><span class=\"min-w-[100px] mr-2 inline-block font-bold\">$label:</span><span class=\"text-slate-500\">$value</span></li>"; } ?>

January 7, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.