lundi 21 décembre 2020

Displaying 4 complex random divs from array list

I am trying to make a carousel which displays 4 random posts. I came across a simple random div display from another thread

$divs = array(
'<div id="divZero">Start Div</div>',
'<div id="divFirst">First Div</div>',
'<div id="divSecond">Second Div</div>',
'<div id="divThird">Third Div</div>',
'<div id="divFourth">Fourth Div</div>',
'<div id="divFifth">Fifth Div</div>',
'<div id="divSixth">Sixth Div</div>'
);

// Array with 4 random keys from $divs
$randKeys = array_rand($divs, 4);

echo $divs[$randKeys[0]]; // First random div
echo $divs[$randKeys[1]]; // Second random div
echo $divs[$randKeys[2]]; // Third random div
echo $divs[$randKeys[3]]; // Fourth random div

The problem is I am using classes for the divs and the wrapping is not simple, and I am incorporating Google Analytics tracking code. When I try it with my div set up, I get the 417 - Expectation Failed error. Was wondering if anyone might be able to help me sort this out.

The divs use class formats since they repeat, but the link, title (and GA label names) change. Here is an example of 2

<div class="rec-wrap clearfix">
    <div class="rw-image"><a href="https://www.website.com/linkA" onclick="ga('send', 'event', { eventCategory: 'Evergreen', eventAction: 'Click', eventLabel: 'Story Title A'});"><img src="https://website.com/imageA.jpg" width="80" height="80"></a></div>
    <div class="rw-title"><a href="https://www.website.com/linkA" onclick="ga('send', 'event', { eventCategory: 'Evergreen', eventAction: 'Click', eventLabel: 'Story Title A'});">Story Title A</a></div>
</div>

<div class="rec-wrap clearfix">
    <div class="rw-image"><a href="https://www.website.com/linkB" onclick="ga('send', 'event', { eventCategory: 'Evergreen', eventAction: 'Click', eventLabel: 'Story Title B'});"><img src="https://website.com/imageB.jpg" width="80" height="80"></a></div>
    <div class="rw-title"><a href="https://www.website.com/linkB" onclick="ga('send', 'event', { eventCategory: 'Evergreen', eventAction: 'Click', eventLabel: 'Story Title B'});">Story Title B</a></div>
</div>



Aucun commentaire:

Enregistrer un commentaire