0

I am starting out with PHP for a WordPress and have written some code to put some social network icons in the footer. The way I have done it works, I'm simply calling the content of social network URL stored in the DB and if there is something the icon/link in the footer. But looks very inefficient to me, here is the code, does anyone know how to make it 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 for 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 us 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 us 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 us on Linkedin"></a></li>
            <?php
             } 
            ?>            

          </ul>
        </div>
      </div>
1
  • 3
    Do you just think it is inefficient, or do you have evidence that it's inefficient? Commented Jun 29, 2013 at 14:30

3 Answers 3

2

Maybe:

  <!-- divs for right social network icons column -->
  <div class="eight columns">
    <div class="social">
      <ul>
        <?php
            foreach (array("twitter","facebook","linkedin") as $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 us on '.ucfirst($option).'"></a></li>'));
        ?>
      </ul>
    </div>
  </div>
Sign up to request clarification or add additional context in comments.

Comments

1

From a performance point of view, I don't think that there is anything to optimize in here, three separate cases tested individually

Comments

0
  <?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'); 

    $icon1 = of_get_option('fab_social_twitter_icon');
    $icon2 = of_get_option('fab_social_facebook_icon'); 
    $icon3 = of_get_option('fab_social_linkedin_icon');          
  ?>



  <!-- divs for right social network icons column -->
  <div class="eight columns">
    <div class="social">
      <ul>

        <?php if(!empty($social1)) { ?>
            <li>
               <a href="<?php echo $social1; ?>">
                  <img src="<?php echo $icon1; ?>" alt="Follow us on Twitter">
               </a>
            </li>
        <?php } ?>

        <?php if(!empty($social2)) { ?>
            <li>
               <a href="<?php echo $social2; ?>">
                  <img src="<?php echo $icon2; ?>" alt="Follow us on Facebook">
               </a>
            </li>
        <?php } ?>

        <?php if(!empty($social3)) { ?>
            <li>
               <a href="<?php echo $social3; ?>">
                  <img src="<?php echo $icon3; ?>" alt="Follow us on Linkedin">
               </a>
            </li>
        <?php } ?>   

      </ul>
    </div>
  </div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.