Recent Topics

1 Jul 07, 2008 12:52    

My b2evolution Version: Not Entered

Hi all,

I want to change the static header logo in my blog and use a php script which is rotating the banners.

The original code in the stylesheet is:

background: transparent url('img/headerimg.jpg') no-repeat center 15px;

I've changes this to:
The original code in the stylesheet is:

background: transparent url('banner/banner.php') no-repeat center 15px;

Unfortunately no banner is displayed when I change the stylesheet from the JPG to the banner. If I then click on "Show background image" in my blog the php file is called and a banner is being displayed:

http://wifi-wue.de/weblog/b2evolution/blogs/skins/simple_zen/banner/banner.php

The address of my blog is blog.wifi-wue.de

Thanks,
Silencer

2 Jul 07, 2008 13:29

I do believe what you want is possible, but I'm not 100% sure.

I achieved similar effect by switching images in the stylesheet. I call the stylesheet as php file

<link rel="stylesheet" href="lunarstyle.php" type="text/css" />


I start the phpstylesheet by sending the correct header:

<?php header( "Content-type: text-css" ); ?>


And now I can use php within the stylesheet.


<?php $random = rand( 1, 3);
$randomimg = 'header' . $random . '.png';
?>
#headerimg {
	background: transparent url('img/<?php echo $randomimg ?>') no-repeat center 15px;
	margin: 0;
	height: 180px;
	*width: 100%;
}

I described this technique in a blog article: http://www.blog.hemminga.net/index.php/B2evo/2007/12/02/conditional-css-through-php but since I didn't invent it, you could also Google for more ideas.

Good luck

3 Jul 07, 2008 18:06

Hi,

Thanks for the feedback.

Does this mean that I have to change the stylesheet file format from stylesheet.css to a stylesheet.php file which I would then call in the _body_header.inc.php and _html_header.inc.php, using your code:


<link rel="stylesheet" href="lunarstyle.php" type="text/css" /> 

The new stylesheet.php would then start with the new header and contain the php code for randomization.

Wouldn't that mean that I have to change all files calling the stylesheet.css?

Regards,
Silencer

4 Jul 07, 2008 18:14

Sometimes writing things down is a big help. I now manage to call the banner file but having some trouble with the index. My banners are called banner1.jpg, banner2.jpg etc. but the file returned is only called banner.jpg

Any ideas?

Thanks,
Silencer

5 Jul 07, 2008 18:34

Of course this cannot work ;-)

It's gotta be:


<?php $random = rand( 1, 3);
$randomimg = 'header' . $random . '.png';
?>

The only thing left are some ugly borders around my image but this time I have no idea how to solve this.

BTW: good feeling that I can still do a little little bit of coding stuff...

6 Jul 07, 2008 18:57

Looks like that works just fine on your blog.
Of course my code had some errors. Note to self: test before you post.

Well done.

--F

7 Jul 07, 2008 19:16

Unless you want to use $randomimg in more than one place in the code then you could save a few cpu cyles, a tad of memory and some hdd space with :

#headerimg {
    background: transparent url('img/header<?php echo rand(1,3); ?>.png') no-repeat center 15px;
    margin: 0;
    height: 180px;
    *width: 100%;
}

¥


Form is loading...