Display a specific when custom field has value
-
On my blog (Bon Bon), I am currently using this bit of code to display a custom field that I manually insert a link into, on posts that I have that use affiliate links:
<?php $affiliates = get_post_meta ($post->ID, 'affiliates', true); ?> <?php if (strlen ($affiliates) > 0): ?> <div class="awrap"><?php echo $affiliates; ?></div> <?php endif; ?>
However, I would like to do something a bit more sophisticated, and display something more along the lines of this:
<?php $affiliates = get_post_meta ($post->ID, 'affiliates', true); ?> <?php if (strlen ($affiliates) > 0): ?> <div class="awrap"><?php echo "<a href="/./affiliates">affiliate link</a>"; ?></div> <?php endif; ?>
By doing so, I want to display a simple
<a href="/./affiliates">affiliate link</a>
regardless of what the value of the custom field is, so long as the custom field$affiliates
has value.I wasn’t able to get the above to execute how I like (i.e., it wound up displaying on every post, which isn’t good, because only some of my posts have affiliate links.
Help is greatly appreciated!
All the best,
Ashley
- The topic ‘Display a specific when custom field has value’ is closed to new replies.