MyBB Community Forums

Full Version: Why this code not work?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i put this code in global.php

//random image

     $logo[0] = "{$mybb->settings['bburl']}/logo/1.jpg";
	 $logo[1] = "{$mybb->settings['bburl']}/logo/2.jpg";
	 $logo[2] = "{$mybb->settings['bburl']}/logo/3.jpg";
	 $logo[3] = "{$mybb->settings['bburl']}/logo/4.jpg";
	 
	 $start = "0";
	 $end = "3";

	 $rand = mt_rand($start, $end);
	 $showlogo = $logo[$rand];

and put this code in Index template...

<center><a href="{$mybb->settings['bburl']}/index.php"><img src="{$showlogo}" alt="{$mybb->settings['bbname']}" title="{$mybb->settings['bbname']}" /></a></center>

Ok... work fine...

but if i put in header template the same code puted in Index template...
Not workSad... Why? Huh
sorry...
solved...
Also, just so you are aware, the center tag is deprecated. You should change it to
<span style="text-align:center"><a href="{$mybb->settings['bburl']}/index.php"><img src="{$showlogo}" alt="{$mybb->settings['bbname']}" title="{$mybb->settings['bbname']}" /></a></span>

(2011-11-16, 06:01 PM)dragonexpert Wrote: [ -> ]Also, just so you are aware, the center tag is deprecated. You should change it to
<span style="text-align:center"><a href="{$mybb->settings['bburl']}/index.php"><img src="{$showlogo}" alt="{$mybb->settings['bbname']}" title="{$mybb->settings['bbname']}" /></a></span>

tested here.. but not work...
i donĀ“t understand why...
image apper but in left...

I changed the code...
better or no?


in global.php

//random image
     
	 $start = "1";
	 $end = "4";
	 $rand = mt_rand($start,$end);

in header template

<center><a href="{$mybb->settings['bburl']}/index.php"><img src="{$mybb->settings['bburl']}/logo/{$rand}.jpg" alt="{$mybb->settings['bbname']}" title="{$mybb->settings['bbname']}" /></a></center> 
Your header template should have the following:
<span style="text-align:center"><a href="{$mybb->settings['bburl']}/index.php"><img src="{$mybb->settings['bburl']}/logo/{$rand}.jpg" alt="{$mybb->settings['bbname']}" title="{$mybb->settings['bbname']}" /></a></span>

It shouldn't contain the center tag. I think that could be affecting it. The code in global.php is better though.
Except that he should stick with starting from 0 and number his images starting at 0 as well Toungue