Haven't been able to find what I'm looking for so far, so I'm asking for help.
I have a div with a class that needs to end in a number between 1 and 8, and I need it to be a random number, without repeating...
<div class="parallax parallax_<?php echo $random_number ?>"></div>
I figured this should be pretty simple, but I'm having trouble.
Currently, I have:
<div class="parallax parallax_<?php echo rand(1, 8); ?>"></div>
which works, but produces duplicates.
EDIT
So after testing, I realized I am running into a problem. I am using this within a wordpress template. I am querying a set of 6 posts, and for each set of posts, I am including the above parallax div. So, I get a random, none repeating number for each query, but each query resets the numbers - giving me duplicates... Here is my entire code.
<?php
$args = array(
'post_type' => 'post',
'orderby' => 'menu_order',
'posts_per_page' => -1,
'order' => 'ASC'
);
$posts = get_posts( $args );
?>
<?php foreach (array_chunk($posts, 6, true) as $posts) : ?>
<div class="parallax parallax_<?php echo rand(1, 8); ?>"></div>
<div class="posts_container">
<?php foreach( $posts as $post ) : setup_postdata($post); ?>
<div class="post">
<div class="post__thumbnail"><a href="<?php the_permalink();?>"><?php the_post_thumbnail(); ?></a></div>
<div class="post__title"><?php the_title(); ?></div>
</div>
<?php endforeach; ?>
</div>
<?php endforeach; ?>