I would like to improve the following code that I posted below. It does the job perfectly, but I just feel like it could definitely be improved. I could easily leave it the way it is but I am trying to learn and that's why I would like to get suggestions from experienced programmers.
Code:
<?php
if($facebook && !$twitter_username || !$facebook && $twitter_username) {
$width = "490";
} else {
$width = "930";
}
?>
<div id="content">
<div style="width:<?=$width;?>px;margin:auto;">
<?php if($facebook) { ?><div class="buttons"><img src="images/facebook_icon.png" class="fb" /> <p><em>Like Us</em><br />on Facebook</p></div><?php } ?>
<?php if($twitter_username) { ?><div class="buttons"><img src="images/twitter_icon.png" class="twitter" /> <p><em>Follow Us</em><br />on Twitter</p><span>@<?=$twitter_username;?></span></div><?php } ?>
</div>
<br class="clear" />
<?php
if($twitter_username) {
if($display_tweets) {
?>
<div class="tweet">
<h2 class="twitter_feed white_textshadow">Latest Tweet</h2>
<div class="feed"></div>
</div>
<?php
}
}
if(!$display_tweets || !$twitter_username) {
if($website_url) {
?>
<h2 class="visit white_textshadow center"><em>Visit Our Website</em><br>www.<?=$website_url;?></h2>
<?php
}
}
?>
</div>
This is for a page where it displays some Social Media information for that user. In the database there are 4 fields:
- facebook (NULL or 1)
- twitter username (NULL or username)
- display_feed (NULL or 1)
- website URL (NULL or url domain.com format)
Any tips on how to improve this, I would really appreciate it. Maybe creating some functions so I don't have to keep having these if and else statements.
Thank you!