I have this code, which I would like to make as small as possible.
As you can see, we are repeating alot of the same HTML code over, but with slight changes.
<?php if( ! $liked_before): // If not liked before, show the link a href?>
<a href="javascript:;" id="action-like">
<div class="action_like" title="Like">
<abbr title="Like">Like</abbr>
</div>
</a>
<?php elseif($liked_before): // else dim it and make non clickable ?>
<p id="action-like" rel="liked_before">
<div class="action_like" title="You Like this" style="opacity: 0.5;">
<abbr title="You Like this">Like</abbr>
</div>
</p>
<?php endif; ?>
Kind of stuck as to how I would condense this into less.
I also have the same code as above straight after, so I have 2 if else statements like this.
As you can see, the only things that change are:
- the
a href=...tag to aptag - the title ‘Like’ -> ‘You like this’
- the
ptag must have the rel, as it is used in the javascript.
Any ideas how I could make this leaner?
Some sort of inline echo.
How would you do it?
I would leave it as is.
From your example, you’re also modifying the HTML within the
<p>or<a>tag (style and abbr attributes), and hacking together something to solve this trivial “problem” would only lead to less readible and harder to manage code. Especially from an efficiency standpoint, there’s nothing to gain here.