Home | Store | osCommerce Tutorials

osCommerce Main Categories Header

Part 1 - Study code structure of osCommerce Main Categories Header


In this osCommerce tutorial, we will study the code or file structure of the Main Categories Header. If you already read our New Products Header before, you should noticed that the code structure of Main Categories Header is almost the same as the New Products Header. Yes... osCommerce file structure shares the same class to display the box headers, therefore the codes structure are almost the same.

Open the includes/boxes/categories file.

The following three lines of codes under the tep_show_category() function of categories.php is used to display the osCommerce Main Categories Header.

$info_box_contents = array();
$info_box_contents[] = array('text' => BOX_HEADING_CATEGORIES);

new infoBoxHeading($info_box_contents, true, false);

osCommerce Customization Tips:
Remove the osCommerce Main Categories Header by commenting the above three lines of codes

osCommerce Main Categories Box Header

Let's discuss this three lines of codes one by one.

$info_box_contents = array();

The first line simply create a new array with $info_box_contents variable name. Now this new array is empty, i.e. the new array contains no any value.

$info_box_contents[] = array('text' => BOX_HEADING_CATEGORIES);

After a new array has been created. The next step is usually to add value(s) to the array. Unlike a normal variable, a key is required for each value.

The second line of code is use to assign a value to the array:

  • the value is "BOX_HEADING_CATEGORIES"
  • the name of key of this value is "text

The BOX_HEADING_CATEGORIES is defined in the catalog/includes/languages/language.php file. In this example, the BOX_HEADING_CATEGORIES is defined in the catalog/includes/languages/english.php file, line 73.

define('BOX_HEADING_CATEGORIES', 'Categories');

osCommerce the BOX_HEADING_CATEGORIES

If you check the value of $info_box_contents like this:

print_r ($info_box_contents);

The output of the $info_box_contents will be:

Array ( [0] => Array ( [text] => Categories ) )

If you like a better looking output, you can use:

echo '<pre>';
$info_box_contents = array();
$info_box_contents[] = array('text' => BOX_HEADING_CATEGORIES);
print_r($info_box_contents);
echo '</pre>';

The output of the $info_box_contents will then be more readable:

Array
(
[0] => Array
(
[text] => Categories
)

)

Note that the $info_box_contents is a two-dimensional array. We need both row index and column index to reference to element of the array.

In the above example, the row index is "0" and the column index is "text". Therefore the value of the "Categories" can be obtained by:

echo $info_box_contents[0]["text"];

The output of this code will be:

Categories

Now the $info_box_contents array contains the value of Main Categories Header (i.e. Categories). We have enough information to display the Main Categories Header. Like previous tutorials, this is a good idea to see if we can write the codes on our own to get the same result.

In the next osCommerce tutorial, we are going to write our own codes to display the osCommerce Main Categories Header on the webpage. After we write our own osCommerce codes, we will also study how the original osCommerce codes work.