Joomla! Discussion Forums



It is currently Sun Nov 22, 2009 4:17 am (All times are UTC )

 


Forum rules

Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.



Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Background image
Posted: Thu Nov 24, 2005 4:04 am 
User avatar
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Wed Aug 24, 2005 9:05 am
Posts: 272
Location: Batam-Indonesia
dear all,
I just release a new version of my client pks-batam.or.id an Indonesian language website from $ambo to Joomla 1.0.4.
I put a background image controled on template_css.css here:

body {
color: #000000;
margin-top: 0px;
margin-bottom: 0px;
padding: 0px;
font-family: arial,verdana,sans-serif;
font-size: 11px;
background-image: url(../images/bck2.gif);
}
My question, can I change randomly a background image with another images that I have? -> free background pattern on http://http://squidfingers.com/patterns/.

thnks and regards

aris-


Top
   
 
 Post subject: Re: Background image
Posted: Thu Nov 24, 2005 6:42 am 
Joomla! Enthusiast
Joomla! Enthusiast
Offline

Joined: Wed Sep 07, 2005 6:45 pm
Posts: 245
Not directly through the stylesheet, but yes, it is possible, however, you will have to write a script that will dynamically alter tag of the template.
a possible methodology:

place the extra images in a dedicated directory in the template directory
write the script to do the following
  • look in the dedicated directory
  • get all image filenames, and put in an array
  • get the number of entries in the array
  • create a random generator, using the number of entries in the array as top limit.
  • use the returned random number to select an entry from the array as a variable

edit the tag of template index.php to include
style="background-image:

_________________
http://www.themeresources.com


Top
  E-mail  
 
 Post subject: Re: Background image
Posted: Thu Nov 24, 2005 7:13 am 
User avatar
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Wed Aug 24, 2005 9:05 am
Posts: 272
Location: Batam-Indonesia
thak you phil,
basicly understand. but I am not a coder  :(. my based on design. so...it's difficult for me to realize into the code (script).
ehmm..could you create please? I think usefull for other person. ;)

rgds
aris-


Top
   
 
 Post subject: Re: Background image
Posted: Thu Nov 24, 2005 5:04 pm 
User avatar
Joomla! Guru
Joomla! Guru
Offline

Joined: Fri Aug 19, 2005 2:46 am
Posts: 777
Location: Washington State, USA
You could look at this post where the header image changes based on days of the week as well. Maybe just simplify the code he is using.

_________________
New to Joomla? :) Make sure2 visit:
\_Anna's Joomla Tips - index.php/topic,5503.0.html


Top
   
 
 Post subject: Re: Background image
Posted: Fri Nov 25, 2005 12:04 am 
Joomla! Enthusiast
Joomla! Enthusiast
Offline

Joined: Wed Sep 07, 2005 6:45 pm
Posts: 245
aris wrote:
thak you phil,
basicly understand. but I am not a coder  :(. my based on design. so...it's difficult for me to realize into the code (script).
ehmm..could you create please? I think usefull for other person. ;)

rgds
aris-

You claim not to be a coder.
I will claim to be not much of a coder ;)
anyway.... the following tested on Joomla! 1.0.3, running on baobab server...

Create a directory in your template directory, at the same level as index.php, called    random
Put some images into the new directory (might like to update your xml file as well)
Make your body tag look something like this:
Code:
<body <?php echo RandomBackground();?> >

and then put the following at the very very end of your index.php
Code:
<?php
function RandomBackground(){
$bgFile_array = Array();
$fullDir= $GLOBALS['mosConfig_absolute_path']."/templates/".$GLOBALS['cur_template']."/random/";
$handle = opendir($fullDir); // open 'random' directory in template directory (should have the images)
while (false !== ($file = readdir($handle))) {
   if ($file != "." && $file != "..") {
   $val=explode(".",$file); // separates filename from extension
   if ($val[1]=='jpg' or $val[1]=='png'or $val[1]=='gif'){ // tests extension for compliance to restrictions
   $bgFile_array[] = $val[0].".".$val[1];} //rejoins name and extension
   }
}
closedir($handle);
$random_top = count($bgFile_array); // counts how many entries in the array
$selector = rand(1,$random_top)-1; // chooses what position in array to get the image
$style_output = "style=\"background:url('".$GLOBALS['mosConfig_live_site']."/templates/".$GLOBALS['cur_template']."/random/".$bgFile_array[$selector]."') top left repeat;\""; // generates the style code.
return $style_output;
}
?>


This code looks in the directory named  'random', and selects only jpg,gif or png files.
You could use this in body, div, or table to vary the background randomly.
I would still recommend having the background-image defined in the default style sheet as well... just in case ;)

Hope it helps you out.

_________________
http://www.themeresources.com


Top
  E-mail  
 
 Post subject: Re: Background image
Posted: Fri Nov 25, 2005 3:49 am 
I've been banned!
Offline

Joined: Thu Aug 18, 2005 12:37 am
Posts: 1139
Location: Melbourne, Australia
Or you could just include a randomised id that cascades through the body..

i.e




#page1 has 1 image, #page2 has another and so on.. Just remember to keep everything apart from the image calls themselves in the body CSS definition.

I use this on my own site.. (nice rotating images via CSS is way cool) 8) 8)

All in all, it's only 2 extra lines of code in the template itself. The CSS will have varying mileage, as I use over a dozen rotating images on my site, which means it can be done through the stylesheet. ;D


Last edited by absalom on Fri Nov 25, 2005 3:58 am, edited 1 time in total.

Top
  E-mail  
 
 Post subject: Re: Background image
Posted: Fri Nov 25, 2005 4:33 am 
User avatar
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Wed Aug 24, 2005 9:05 am
Posts: 272
Location: Batam-Indonesia
Amazing! Great!
Thank you Phil,. it's work fine. And now, was applied in my website client - see http://www.pks-batam.or.id

best rgd
aris-


Top
   
 
 Post subject: Re: Background image
Posted: Fri Nov 25, 2005 4:36 am 
User avatar
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Wed Aug 24, 2005 9:05 am
Posts: 272
Location: Batam-Indonesia
focalguy wrote:
You could look at this post where the header image changes based on days of the week as well. Maybe just simplify the code he is using.


thank you .. focalguy. will be try

best rgd
aris-


Top
   
 
 Post subject: Re: Background image
Posted: Fri Nov 25, 2005 4:55 am 
Joomla! Enthusiast
Joomla! Enthusiast
Offline

Joined: Wed Sep 07, 2005 6:45 pm
Posts: 245
@aris
Glad it was of use.
***Started typing, and testing Absolam's method before Aris's reply, so now posting in general to show the implementation of this method for any non-coders interested***
absalom wrote:
Or you could just include a randomised id that cascades through the body..
i.e

#page1 has 1 image, #page2 has another and so on.. Just remember to keep everything apart from the image calls themselves in the body CSS definition.
I use this on my own site.. (nice rotating images via CSS is way cool) 8) 8)

All in all, it's only 2 extra lines of code in the template itself. The CSS will have varying mileage, as I use over a dozen rotating images on my site, which means it can be done through the stylesheet. ;D

Horses for courses-- which is not a criticism, just a fact.
This is yet another solution. However, it means that filenames are hardcoded in the css (ok for static items).
Depending on your needs, Absalom's solution may well be the better choice.
Following his method, you would have in your css, something like
Code:
#page1{
background: url(../images/indent3.png) top left repeat;
}
#page2{
background: url(../images/01.gif) top right repeat-y;
}
... etc

and in the index.php file
Code:
<?php $random_top = 2; // you would have to set this using the number of css entries as above.
$random = rand(1, $random_top); //pick a number any number ?>
<body id="page<?php echo $random;?>">

(I have left the $random_top to seperate the max level of the random generator.)
It means editing css each time you change/add/remove an image, and considering the amount of css code, not difficult at all.
[edit]-- also means you have tight control over the images in rotation, and can stop one or more by editing css. [/edit]
The method I put up, allows you to just drop images into the dedicated directory, and they will be selected.
[edit]-- to remove image from rotation, you need to delete the image from the directory [/edit]

As I said, horses for courses.
Choose your steed :D :P

_________________
http://www.themeresources.com


Last edited by philmoz on Fri Nov 25, 2005 5:07 am, edited 1 time in total.

Top
  E-mail  
 
 Post subject: Re: Background image
Posted: Fri Nov 25, 2005 5:44 am 
I've been banned!
Offline

Joined: Thu Aug 18, 2005 12:37 am
Posts: 1139
Location: Melbourne, Australia
Your idea of my random code is still too long.

The code for $random is simply:
Code:
$random = rand(1,9);

which I usually dump in the first PHP call, being the J! or die statement. You don't need two lines to determine the maximum random images. All you need to do is determine how many random images you want on a page.

The reason my CSS for my own site is so long is that I'm rotating nearly 20 images on 2 layouts using this effect.  8)

I'm thinking of expanding this out to 50 with my new layout.


Last edited by absalom on Fri Nov 25, 2005 5:45 am, edited 1 time in total.

Top
  E-mail  
 
 Post subject: Re: Background image
Posted: Fri Nov 25, 2005 6:16 am 
Joomla! Enthusiast
Joomla! Enthusiast
Offline

Joined: Wed Sep 07, 2005 6:45 pm
Posts: 245
absalom wrote:
Your idea of my random code is still too long.

The code for $random is simply:
Code:
$random = rand(1,9);

That pretty much dawned on me about half hour after posting, that what I put up was -- messy  -- but then, I'm unashamedly a hack, not a coder ;)
Quote:
which I usually dump in the first PHP call, being the J! or die statement. You don't need two lines to determine the maximum random images. All you need to do is determine how many random images you want on a page.

The reason my CSS for my own site is so long is that I'm rotating nearly 20 images on 2 layouts using this effect.  8)

I'm thinking of expanding this out to 50 with my new layout.

Out of curiosity, would you be tempted to use code similar to that which I posted as an included function file, and use it to generate an inline style to extend the tag?
ie, to output
Code:
<style>body{background-image:url("../image_directory/image");}</style>


Or is that still, IYHO, overdoing it - so to speak?

_________________
http://www.themeresources.com


Top
  E-mail  
 
 Post subject: Re: Background image
Posted: Fri Nov 25, 2005 9:12 am 
I've been banned!
Offline

Joined: Thu Aug 18, 2005 12:37 am
Posts: 1139
Location: Melbourne, Australia
It's overkill.

You can point to whatever file and directory you want using the CSS background image call, and that way, it doesn't require inline CSS (which I find to be a waste of resources - you have a CSS file, use it  8) ).

You could even point to another server if you wanted to to source the images (say, if you have a dedicated image library server?) ;D


Top
  E-mail  
 
 Post subject: Re: Background image
Posted: Wed Dec 07, 2005 12:20 am 
User avatar
Joomla! Intern
Joomla! Intern
Offline

Joined: Fri Sep 02, 2005 8:45 pm
Posts: 99
Location: Peru - The Land for All Your Senses
Hey guys, I am searching for hours how to call a module from my css file.

I am trying this without success:

Code:
#headerbox {
   position:absolute;
   left:0px;
   top:58px;
   width:640px;
   height:94px;
   z-index:3;
        background-image: <?php mosLoadModules ( 'advert1' ); ?>;
   background-repeat: no-repeat;
}


But the background image doesnt show.
any help?

_________________
Javier Yep Garcia
SEO & Website Solutions Expert
http://www.godmarketing.com
http://www.javieryep.com


Top
  E-mail  
 
 Post subject: Re: Background image
Posted: Wed Dec 07, 2005 1:20 am 
I've been banned!
Offline

Joined: Thu Aug 18, 2005 12:37 am
Posts: 1139
Location: Melbourne, Australia
Never call PHP from a CSS file. It simply won't work.


Top
  E-mail  
 
 Post subject: Re: Background image
Posted: Wed Jan 11, 2006 1:12 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Fri Dec 16, 2005 2:47 pm
Posts: 10
Just wanna say thank you guys for this thread. Long have I waited for such a solution. You don't know how much you have helped me (and I'm pretty sure most newbies as well). Thanks so much ! :)

In case you've encountered Maarten Robben's random background module, you may want to shed light.  :)  His module can be downloaded at http://mamboforge.net/projects/randombg


Top
  E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

Quick reply

 



Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group