I've run into this situation a couple of times where a customer wants to have a different image on the background of every page. This isn't such a big if I'm building and mainting the site as it's just a matter of a CSS lines for each page but when they want to be able to maintain the site themselves, then there has to be a very easy method for them to add the photos for the background for each page.

I decided on the following process. They would upload a file to a specific directory /images/backgrounds and give the background image a name that was the id of the article. For example, the home page would have a background of 1.jpg.

Once I had decided on this method, I created a new css file that included the following lines:

#body_wrap.t1 {background: url(../../../images/backgrounds/1.jpg); background-repeat:no-repeat; min-width: 100%;}

and I pre-populated this file with as many entries as I thought would eventually be on the site.

Then, I added some code to the start of the article to get the id of each article:

<?php
        $option = JRequest::getCmd('option');
        $view = JRequest::getCmd('view');
        if ($option=="com_content" && $view=="article")
        {
        $ids = explode(':',JRequest::getString('id'));
        $article_id = $ids[0];
        $article =& JTable::getInstance("content");
        $article->load($article_id);
        }
    ?>

I wrapped all of the content of the template's index.php site in

<div id="body_wrap" class="t<?php echo $article_id;">"</div>

And this worked.

Then I realized that it would be much cleaner if I put the class creation as an incidental style definition within the index.php file.

<div id="body_wrap" style="background: url(/<?php echo $this->baseurl ?>/images/backgrounds/<?php echo $article_id;?>.jpg); background-repeat:no-repeat; min-width: 100%"></div>

This gets it all dynamically generated from within the index.php file. You no longer need the additional css file and it will keep working for as many articles are added to the site.

The one drawback to this approach, is that it doesn't work when you have links to items that aren't articles such as contact pages or other components driving the main content area of your site. For these, I just set a default.