Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8931329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:05:37+00:00 2026-06-15T09:05:37+00:00

I asked a question previously – HERE – about how I could set my

  • 0

I asked a question previously – HERE – about how I could set my border-color to a random color. I have this working.

As you’ll see, I have a possible 7 colors in my array. How can I edit my code so that once a color has been chosen, it won’t be reused. There are 3 divs on my page that the color will be used on, so I’d like 3 different colors from the possible 7.

Full code of how I’m using it:

<div id="featured-posts" class="container_12">
<?php
 global $post;
 $myposts = get_posts('numberposts=3&category=12');
 foreach($myposts as $post) :
 ?>

 <?php global $post; ?>
    <?php
    $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 5600,1000 ), false, '' );
    ?>

        <?php
            $colors = array("#000000", "#949c51", "#571c1e", "#f36533", "#782a80", "#f6a41d", "#ed1b24");
            $randomColor = $colors[array_rand($colors)];
        ?>

<a href="<?php the_permalink(); ?>">
<div class="grid_4 featured-home" style="background: url(<?php echo $src[0]; ?> ) !important;">
    <div class="featured-details" style="border-color: <?php echo $randomColor; ?>;">   
        <h4 style="color: <?php echo $randomColor; ?>;"><?php the_title(); ?></h4>
        <p><?php the_excerpt(); ?>  <q style="color: <?php echo $randomColor; ?>; font-weight:bold !important;">Read more &gt;</q></p>
    </div>
    <div class="featured-lower" style="border-color: <?php echo $randomColor; ?>;"></div>
</div></a>
 <?php endforeach; ?>
 </div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:05:38+00:00Added an answer on June 15, 2026 at 9:05 am

    You could shuffle and then pop the last element off the array each time:

    Define your colours array once (this would need to be removed from your loop):

    $colors = array("#000000", "#949c51", "#571c1e", "#f36533", "#782a80", "#f6a41d", "#ed1b24");
    

    Then each time you use randomColor you shuffle it and remove the last element of the array to use:

    shuffle($colors);
    $randomColor = array_pop($colors);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an extension of a question I previously asked here . Long story
I asked a question about this previously but my database structure has changed, and
I have asked a similar question previously but it was never resolved so here
I have asked a variation of this question previously for Hibernate. However, I am
This question was previously asked Here , but not answered, And failed to find
I have previously asked a question about how can I write a code block
I've previously asked a question of about Delegates does anyone have a must have
I previously asked this question about how to make versioned serializaion using boost::serialization::access I
Sorry if this is a repeat of a question asked previously, but I have
I have seen this question asked previously but can not find a clear explanation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.