I am working with a client's wordpress affiliate site.
We are using two plugins in conjunction with each other.
- ACF (Advanced Custom Fields)
- EasyAzon (This inserts an affiliate link via shortcode into your post)
I have set up custom fields for this shortcode, and coded it into my them like this.
<div class="top-link"> <?php the_field('link-button'); ?></div>
This outputs:
"<div class="top-link"> <a href="http://ift.tt/1Q3k7Jp">Buy Now</a> </div>
"
And now I want to use the same function "<?php the_field('link-button'); ?>
" at the bottom of my page.
However I would like it to display text from yet another ACF field "<?php the_field('bottom-link'); ?>
" within the anchor tag.
But if there is no text in that field, I want it to use the text "Click to buy on Amazon"
So here is what I have:
<div class="top-link"><?php the_field('link-button'); ?></div>
<!-- The post content -->
<div class="bottom-link"> <?php the_field('link-button'); ?></div>
<?php
$link = get_field('bottom-link');
if (get_field('bottom-link') != '') {
$link = get_field('bottom-link');
}
else {
$link = "Click to Buy Amazon";
}
?>
<script>
var link = '<?php echo $link; ?>';
jQuery( document ).ready(function() {
jQuery('.bottom-link a').text(link);
});
</script>
I'm pretty new to both languages, and maybe complicating things a lot. Any thoughts would help!
Here is the dev site live if you're interested in looking at that.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire