Using Joomla for Individual Background Images PDF Print E-mail
Written by Steven Johnson   
Thursday, 17 May 2007
ImageRecently I had the need to have different background images on different pages.  With a non content management system this would not be that big of a deal.  Since I needed the background images to cover the entire page and have the ability to specify which images, using a static body tag would not work.  After some thought and research I was able to devise a solution using PHP.
  • 1. Find an unique value that would be on each web page, such as the "Title" or the "Title Alias".  I chose "Title Alias".  This value has more of an interal use and I was already using the title field for my Seach Engine Friendly URL's.  The jlleblanc at the Joomla forums were nice enough to provide me with the following code to locate the "Title Alias" value:

    global $database;
    $id = mosGetParam($_REQUEST, 'id', 0);
    $row = new mosContent($database);
    $row->load($id);
    echo $row->title_alias;
  • 2. I then took this value and entered it into a PHP statement that would generate my opening body tag.  You will need to adjust the path of the background image file to fit your situation.  I also commented out the echo $row-?title_alias; line.  I do not need to print thisvalue to the screen.

    <?php
    global $database;
    $id = mosGetParam($_REQUEST, 'id', 0);
    $row = new mosContent($database);
    $row->load($id);
    //echo $row->title_alias;

    echo "<body background=\"/images/stories/background/$row->title_alias\" bgcolor=\"#ffffff\">"
    ?>
  • 3. Change the value of the title alias in the joomla admintrator panel to the name of the background image file.  This will need to be done for each web page that you want to specify the background image.  You now have the ability to specify which background image gets used on which page.

  • 4. Here is the output that is generated for each page:

    <body background="/images/stories/background/dandelion_seedstripe3.jpg" bgcolor="#ffffff"> 

     

  • 5. A fancier version of this mod may include if then and else if statement.  For right now this was able to meet my requirements.

     

Any thoughts?  What can be improved?  Was this helpful to you? 

Trackback(0)
Comments (3)Add Comment

Write comment
quote
bold
italicize
underline
strike
url
image
quote
quote
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley

security code
Write the displayed characters


busy
Last Updated ( Thursday, 17 May 2007 )
 
< Prev

Welcome to Dr. Retarded

Here at Dr. Retarded you will find Photos of most of the places that I have been and information on many things that I would like to do. 

Hope you like the site!