Home | Store | osCommerce Tutorials

osCommerce Main Content Display Summary

The following block of PHP codes (line 15 - 32) at the top of osCommerce homepage (index.php) determine what the contents of the Main Content (Body text) will be displayed. The secret is the $category_depth variable.

// the following cPath references come from application_top.php
$category_depth = 'top';

if (isset($cPath) && tep_not_null($cPath)) {
$categories_products_query = tep_db_query("select count(*) as total from " .
TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id = '" . (int)$current_category_id . "'");
$cateqories_products = tep_db_fetch_array($categories_products_query);

if ($cateqories_products['total'] > 0) {
$category_depth = 'products'; // display products
} else {
$category_parent_query = tep_db_query("select count(*) as total from " .
TABLE_CATEGORIES . " where parent_id = '" . (int)$current_category_id . "'");
$category_parent = tep_db_fetch_array($category_parent_query);

if ($category_parent['total'] > 0) {
$category_depth = 'nested'; // navigate through the categories
} else {
$category_depth = 'products'; // category has no products, but display the 'no products' msg
}
}
}

As you can see, the value of $category_depth passing down to the main program may be top, nested or products:

  • $category_depth = 'top'
  • $category_depth = 'nested'
  • $category_depth = 'products'

The picture below summarize how the contents of Main Content of osCommerce homepage will be displayed according to the value of $category_depth passing to the main program.

osCommerce category_depth value

Now, we know how the $category_depth variable control the contents display on the Main Content of osCommerce homepage.