OK, here's a multi-multi-stacking version. It first checks for an individual product image, then for a generic '_product_info' image, then for category images as before. Replace the entire content of smart_backgrounds_functions.php with this. Save the original file elsewhere first as a backup.
PHP Code:
<?php
/**
* @package templateSystem
* @copyright Copyright 2010 Glenn Herbert
* @copyright Portions Copyright 2003-2007 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* /includes/functions/extra_functions/smart_backgrounds_functions.php gjh42 2010-02-10 test 2010-02-17
* Smart Backgrounds by Glenn Herbert (gjh42)
*
* Call this function from any file where page-dependent coding is desired.
* $smart_image = smart_backgrounds();
* Include string arguments if you want to use other than '.gif' images or look for other than 'bg' files.
* $smart_image = smart_backgrounds('.jpg','sidebox'); //returns '_23' if smartsidebox_23.jpg exists
* Use the value of $smart_image to set a classname, filename or other event management when a corresponding image file exists.
*/
function smart_backgrounds($ext='.gif', $location='bg'){
$smart_image = '';
if ($_GET['main_page'] == 'index' or $_GET['main_page'] == 'product_info') {
// _p and products_id only if individual prod bg image exists, else _product_info only if page bg image exists, else _ and cPath only if individual cat bg image exists, else _ and top cat id only if top cat bg image exists
$smart_image = ($_GET['main_page'] == 'product_info' and file_exists(DIR_WS_TEMPLATE_IMAGES . 'smart' . $location . '_p' . $_GET['products_id'] . $ext))?'_p' . $_GET['products_id']:(($_GET['main_page'] == 'product_info' and file_exists(DIR_WS_TEMPLATE_IMAGES . 'smart' . $location . '_product_info' . $ext))?'_product_info':
(file_exists(DIR_WS_TEMPLATE_IMAGES . 'smart' . $location . '_' . $_GET['cPath'] . $ext)?'_' . $_GET['cPath']:(file_exists(DIR_WS_TEMPLATE_IMAGES . 'smart' . $location . '_' . (int)$_GET['cPath'] . $ext)?'_' . (int)$_GET['cPath']:'')));
} elseif ($_GET['main_page'] == 'page') { // _page and ez-page id only if ez-page id bg image exists, else _page only if general ez-page bg image exists
$smart_image = file_exists(DIR_WS_TEMPLATE_IMAGES . 'smart' . $location . '_page' . $_GET['id'] . $ext)?'_page' . $_GET['id']:(file_exists(DIR_WS_TEMPLATE_IMAGES . 'smart' . $location . '_page' . $ext)?'_page':'');
} else { // _ and page base only if page bg image exists
$smart_image = file_exists(DIR_WS_TEMPLATE_IMAGES . 'smart' . $location . '_' . $_GET['main_page'] . $ext)?'_' . $_GET['main_page']:''; //if no images are found $smart_image will be blank
}
return $smart_image;
} ?>
Let me know how this works, and I will adjust if needed.
Oh yes, name the images like smartbg_p123.gif or smartbg_product_info.gif.