PHP isn’t so bad once you get the hang of it! The use of the glob() function allowed me to query all images in a given folder, and stick them in an array. So now I can dynamically update my header images without having to mess with the PHP code itself. The important segment is found in header.php, or header-xxxx.php depending on what you’re calling:
<?php
$imgarray = glob("./wp-content/headers/homepage/\*.\*",1);
$cnt = count($imgarray);
$rn = rand(0,$cnt-1);
$img = $imgarray[$rn];
?>
FYI glob() requires an absolute path…so you can’t simply use the content_path() function as I was before. However, now I can drop all the images I want into wp-content/headers/homepage and they will automatically be added to the list of possible images. I just have to remember to crop them properly to 1040x250 or they’ll show up as their original size.

Comments

comments powered by Disqus