1

Trying to get this to function, randomly chooses 1 of the 3 color choices. Is rand only capable of generating numbers? or Numbers/letters in a series.

<div onclick="location.href='<?php the_permalink() ?>';" style="cursor:pointer;background:#<?php echo rand (DDCA73, A0AA47, ADBAE1)?>;" class="post bg thickbox" id="thickbox post-<?php the_ID(); ?>"> 
2
  • possible duplicate of PHP randomly select from a list Commented Aug 12, 2010 at 1:57
  • 1
    not from that link - ha I guess the wordpress theme I am attempting to modify was created by someone who obviously uses stack overflow too! Commented Aug 12, 2010 at 2:30

1 Answer 1

1

** rand or mt_rand randomize numbers not strings. Create an array, then randomize it's key selection.

<?php function random_color(){ $colors_avail = array("DDCA73","A0AA47","ADBAE1"); $colors_count = count($colors_avail)-1; $color_wheel = $colors_avail[mt_rand(0,$colors_count)]; echo $color_wheel; } ?> <div onclick="location.href='<?php the_permalink() ?>';" style="cursor:pointer;background:#<?php random_color(); ?>;" class="post bg thickbox" id="thickbox post-<?php the_ID(); ?>"> 
Sign up to request clarification or add additional context in comments.

1 Comment

I'm getting FATAL ERROR:Cannot redeclare random_color() Any ideas?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.