wordpress - Make multiple PHP if statements more efficient -
i starting out php wordpress , have written code put social network icons in footer. way have done works, i'm calling content of social network url stored in db , if there icon/link in footer. looks inefficient me, here code, know how make more efficient.
<?php $social1 = of_get_option('fab_social_twitter_url'); $social2 = of_get_option('fab_social_facebook_url'); $social3 = of_get_option('fab_social_linkedin_url'); ?> <!-- divs right social network icons column --> <div class="eight columns"> <div class="social"> <ul> <?php if(!empty($social1)) { ?> <li><a href="<?php echo of_get_option('fab_social_twitter_url'); ?>"><img src="<?php echo of_get_option('fab_social_twitter_icon'); ?>" alt="follow on twitter"></a></li> <?php } ?> <?php if(!empty($social2)) { ?> <li><a href="<?php echo of_get_option('fab_social_facebook_url'); ?>"><img src="<?php echo of_get_option('fab_social_facebook_icon'); ?>" alt="follow on facebook"></a></li> <?php } ?> <?php if(!empty($social3)) { ?> <li><a href="<?php echo of_get_option('fab_social_linkedin_url'); ?>"><img src="<?php echo of_get_option('fab_social_linkedin_icon'); ?>" alt="follow on linkedin"></a></li> <?php } ?> </ul> </div> </div>
maybe:
<!-- divs right social network icons column --> <div class="eight columns"> <div class="social"> <ul> <?php foreach (array("twitter","facebook","linkedin") $option) ($tmp=of_get_option('fab_social_'.$option.'_url')) && (print('<li><a href="'.$tmp.'"><img src="'.of_get_option('fab_social_'.$option.'_icon').'" alt="follow on '.ucfirst($option).'"></a></li>')); ?> </ul> </div> </div>
Comments
Post a Comment