from a pool of H2 texts at random
<h2><?php
$input = array(
"x",
"y",
"z",
"a",
"b"
);
$rand_keys = array_rand($input, 1);
echo $input[$rand_keys[0]];
?></h2>
(not tested) more or less the direct example from:
http://php.net/manual/en/function.array-rand.php
(not primarily a WordPress problem – please try to learn php through web search and web tutorials)
display a banner image on the static front-page
<?php if( is_front_page() ) { ?>
HEADER BANNER HERE
<?php } ?>
http://codex.wordpress.org/Function_Reference/is_front_page
alchymyth,
Thank you kindly for your reply. The header banner worked perfectly.
I did some searching on the php.net/manual site and am learning quite a bit. However, I had one more question in regards to the array. How do you activate the is_front_page tag to work on FALSE boolean searches. That is, if the page is NOT the front_page I would like the following to return. This code works, but will apply to all pages, even the front_page, where two H2 headers would show up, and I only want one.
<h2 class="intro">
<?php
$input = array("...because the little things make a difference.", "...because there’s always one more thing to do.",
"...because we listen to your wishes.",
"...because we can make your day perfect.");
$rand_keys = array_rand($input, 2);
echo $input[$rand_keys[0]] . "\n";
?>
</h2>
I tried the following. It supplies a return of an empty H2 section. as if it is the front_page, when it is not:
<h2 class="intro">
<?php if( is_front_page(FALSE) ) {
$input = array("...because the little things make a difference.", "...because there’s always one more thing to do.",
"...because we listen to your wishes.",
"...because we can make your day perfect.");
$rand_keys = array_rand($input, 2);
echo $input[$rand_keys[0]] . "\n"; } ?>
</h2>
Again, please just direct me to a place to look, because I’m not sure of the terminology for which to search.
Also, is there a php syntax checker?
Thanks,
Dave
if the page is NOT the front_page
if( !is_front_page() )
again a fundamantal php problem…
http://php.net/manual/en/language.operators.logical.php
http://www.w3schools.com/php/php_operators.asp
alternative:
<?php if( is_front_page() ) : ?>
do one thing for the front page
<?php else : ?>
do something else on NOT front pages
<?php endif; ?>
Thanks again. if( !is_front_page() ) worked like a charm.