• Resolved Jaqueline

    (@jaqueline)


    I loved the theme, and I used in my aunt’s blog. But she decided that she wants just some colors to appear in the site (her favorite colors, in shades of pink, red, purple… she wants to avoid the brown, for example).
    There is any way to do it?
    Thanks!!

Viewing 12 replies - 1 through 12 (of 12 total)
  • caemusic

    (@caemusic)

    check out the colors.php…

    it’s gonna take some math skills and basic knowledge of hex colors to do what you want.

    basically rand() php function works like this:
    rand(mininum value, maximum value) so rand(0, 9) like the colors.php file has now will pick a value from 0 to 9 to pick for the hex color.

    the result is echoed inside the “background: #xxxxxx” in the stylesheet. hex colors uses letters and numbers but it looks like the functions will only pick numbers.

    here’s a hex color chart to give you an idea of the limits you will want to put in the rand() function.

    https://www.2createawebsite.com/build/hex-color-chart-grid.html

    actually, the square background colors are defined in the index.php file in the div class=”post bg thickbox”

    pretty much all the other colors are in the colors.php file.

    You could use range() inside your random function. Range supports a-X, where X is a chosen letter in the alphabet.

    Example of range output…

    foreach (range(a,f) as $myletters) {
      echo $myletters.'';
    }

    Would produce…

    a
    b
    c
    d
    e
    f

    Or you could store each value, letters and numbers in an array and pull a value randomly from the array…

    Thread Starter Jaqueline

    (@jaqueline)

    Thanks a lot for the answers!!! I will work on it tomorrow! =)

    Hey Jacqueline do you have finally tweak the color ?
    I try to do the same thing to select only flashy color…

    Hello t31os, do you know how I can store some colors value and pull some randomly, to have a similar result to this one :
    https://www.ikbenmartijn.be

    I have understood that I need to change each rand(0,9) in colors.php and index.php but I’m not a coder and I have no idea of what the code should be instead…

    many thanks to you.

    If you want to use a random array with your own particular values, you can do so like this..

    <?php
    // REF: https://uk.php.net/array_rand
    $myarray = array(
      'one',
      'two',
      'three' );
    
    // 'one' or 'two' or 'three'
    echo $myarray[array_rand($myarray)];
    ?>

    Would output either one, two or three…

    I don’t know this theme myself, but i don’t mind offering up bits of PHP if it helps…

    I’ll need more info on the code you’re using, what you want to do it with it, and how it looks right now if you would like further help.

    ok t31os, in fact each background color use a php rand function repeated 6 times.

    So it’s like this :

    background: #<?php echo rand(0, 9); ?><?php echo rand(0, 9); ?><?php echo rand(0, 9); ?><?php echo rand(0, 9); ?><?php echo rand(0, 9); ?><?php echo rand(0, 9); ?>;

    So if I want to choose only between 4 colors like this color value :
    #F90, #0F0, #F06, #0FF

    How the code should be ?

    thanks

    When it comes to HEX values, possible values are A-F and 0-9, so it’s proberly better to use 1 array, and grab a value this.

    <?php
    	// REF: https://uk.php.net/array_rand
    	$hex_array = array(
    		'a','b','c','d','e','f',
    		'0','1','2','3','4','5','6','7','8','9'
    	);
    
    	echo '#'.
    		$hex_array[array_rand($hex_array)].$hex_array[array_rand($hex_array)].$hex_array[array_rand($hex_array)].
    		$hex_array[array_rand($hex_array)].$hex_array[array_rand($hex_array)].$hex_array[array_rand($hex_array)];
    	?>

    Would output…

    #e6aca7

    #2bdfd2

    and so on….

    Of if you want 3 character values then change the echo for…

    echo '#'.$hex_array[array_rand($hex_array)].$hex_array[array_rand($hex_array)].$hex_array[array_rand($hex_array)];
    	?>

    If you specifically want the values you postsed… then just changes what’s in the array and the echo..

    Like this…

    <?php
    	$hex_array = array(
    		'#F90', '#0F0', '#F06', '#0FF'
    	);
    
    	echo $hex_array[array_rand($hex_array)];
    	?>

    Hope that helps.. ??

    Yes it works ! Thank you so much t31os_ !!!

    No worries, you’re welcome… ??

    Hey all, any idea how to have the WP theme run through the array in sequence? For example, for each sequential post, it runs through slot 1, then 2, then 3, then 4, then starts over at the beginning of the array once it reaches the end?

    I’m basically hoping not to have repeating colors–which you do often get when the colors are randomized.

    Thanks!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘[threattocreativity] How to choose the colors?’ is closed to new replies.