CTA Example: Random Quote
Injecting a random quote CTA into Ajax Load More results.
In this example:
Ajax Load More will use the Call to Actions add-on to insert a random quote into the results of the Ajax query.
JavaScript
The following JavaScript code pulls a random quote from an array and appends the quote to the .ad-callout container returned with Ajax Load More.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
var randomQuote = Array( "Without requirements, programming is the art of adding bugs to an empty text file.", "Before software can be reusable it first has to be usable." ); $.fn.almComplete = function(alm){ if($('.alm-listing.call-to-actions-js').length){ // Target the latest content loaded via Ajax var el = $('.cta-callout .ad-content', alm.el); // Get a random quote var quote = randomQuote[Math.floor(Math.random()*randomQuotes.length)]; // Append random quote to CTA el.html(quote); } }; |
The following shortcode was used to create the CTA Example: Random Quote example.
[ajax_load_more cta="true" cta_position="after:2" cta_theme_repeater="custom-cta.php" posts_per_page="4" images_loaded="true"]
The following Repeater Template was used to create the CTA Example: Random Quote example.
1 2 3 |
<li class="cta-callout"> <div class="ad-content"></div> </li> |