Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Showing main categories with image and link on frontpage


Guest

Recommended Posts

Posted

Hello

I'm currently working on this webshop: www.britpart.no, and I'd like to include the main category images with a link on the frontpage - instead of products of the month.

 

Does anybody know a easy way to do this?

 

Appretiate the help:)

Posted

You might want to check the contributions section if there is a contribution already.

If not, this would require some programming. In case you know a bit about programming here a few pointers:

 

-check the boxes/categories.php file. That's where the categories on the left get created. You might be able to use that and replace some of the html code to display in a similar format then the what's new module. Then replace the what's new call in default.php with the newly created module.

HTH

 

Gunter

Posted

I've looked into the files and located some of the functions. But I was wondering if someone would be kind enough to help me with the code?

I've copied the box and made a "Main categores" file, so it's showing up on my main page, but I basicly need the function to go in there...

 

The new products box looks like this:

<?php

$info_box_contents = array();

$info_box_contents[] = array('text' => sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')));

 

new contentBoxHeading($info_box_contents);

 

if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {

$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);

} else {

$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . $new_products_category_id . "' and p.products_status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);

}

 

$row = 0;

$col = 0;

$info_box_contents = array();

while ($new_products = tep_db_fetch_array($new_products_query)) {

$new_products['products_name'] = tep_get_products_name($new_products['products_id']);

$info_box_contents[$row][$col] = array('align' => 'center',

'params' => 'class="smallText" width="33%" valign="top"',

'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $new_products['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . $new_products['products_name'] . '</a><br>' . $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])));

 

$col ++;

if ($col > 2) {

$col = 0;

$row ++;

}

}

 

new contentBox($info_box_contents);

?>

 

 

And the categories box looks like this:

<?php

/*

$Id: categories.php,v 1.23 2002/11/12 14:09:30 dgw_ Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2002 osCommerce

 

Released under the GNU General Public License

*/

 

function tep_show_category($counter) {

global $foo, $categories_string, $id;

 

for ($a=0; $a<$foo[$counter]['level']; $a++) {

$categories_string .= "  ";

}

 

$categories_string .= '<a href="';

 

if ($foo[$counter]['parent'] == 0) {

$cPath_new = 'cPath=' . $counter;

} else {

$cPath_new = 'cPath=' . $foo[$counter]['path'];

}

 

$categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new);

$categories_string .= '">';

 

if ( ($id) && (in_array($counter, $id)) ) {

$categories_string .= '<b>';

}

 

// display category name

$categories_string .= $foo[$counter]['name'];

 

if ( ($id) && (in_array($counter, $id)) ) {

$categories_string .= '</b>';

}

 

if (tep_has_category_subcategories($counter)) {

$categories_string .= '->';

}

 

$categories_string .= '</a>';

 

if (SHOW_COUNTS == 'true') {

$products_in_category = tep_count_products_in_category($counter);

if ($products_in_category > 0) {

$categories_string .= ' (' . $products_in_category . ')';

}

}

 

$categories_string .= '<br>';

 

if ($foo[$counter]['next_id']) {

tep_show_category($foo[$counter]['next_id']);

}

}

?>

<!-- categories //-->

<tr>

<td>

<?php

$info_box_contents = array();

$info_box_contents[] = array('align' => 'left',

'text' => BOX_HEADING_CATEGORIES

);

new infoBoxHeading($info_box_contents, true, false);

 

$categories_string = '';

 

$categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id = cd.categories_id and cd.language_id='" . $languages_id ."' order by sort_order, cd.categories_name");

while ($categories = tep_db_fetch_array($categories_query)) {

$foo[$categories['categories_id']] = array(

'name' => $categories['categories_name'],

'parent' => $categories['parent_id'],

'level' => 0,

'path' => $categories['categories_id'],

'next_id' => false

);

 

if (isset($prev_id)) {

$foo[$prev_id]['next_id'] = $categories['categories_id'];

}

 

$prev_id = $categories['categories_id'];

 

if (!isset($first_element)) {

$first_element = $categories['categories_id'];

}

}

 

//------------------------

if ($cPath) {

$new_path = '';

$id = split('_', $cPath);

reset($id);

while (list($key, $value) = each($id)) {

unset($prev_id);

unset($first_id);

$categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . $value . "' and c.categories_id = cd.categories_id and cd.language_id='" . $languages_id ."' order by sort_order, cd.categories_name");

$category_check = tep_db_num_rows($categories_query);

if ($category_check > 0) {

$new_path .= $value;

while ($row = tep_db_fetch_array($categories_query)) {

$foo[$row['categories_id']] = array(

'name' => $row['categories_name'],

'parent' => $row['parent_id'],

'level' => $key+1,

'path' => $new_path . '_' . $row['categories_id'],

'next_id' => false

);

 

if (isset($prev_id)) {

$foo[$prev_id]['next_id'] = $row['categories_id'];

}

 

$prev_id = $row['categories_id'];

 

if (!isset($first_id)) {

$first_id = $row['categories_id'];

}

 

$last_id = $row['categories_id'];

}

$foo[$last_id]['next_id'] = $foo[$value]['next_id'];

$foo[$value]['next_id'] = $first_id;

$new_path .= '_';

} else {

break;

}

}

}

tep_show_category($first_element);

 

$info_box_contents = array();

$info_box_contents[] = array('align' => 'left',

'text' => $categories_string

);

new infoBox($info_box_contents);

?>

</td>

</tr>

<!-- categories_eof //-->

 

If it's not too much bother writing the function, I'd really appreciate it!

Posted

Hi Kjetil,

I'm very busy right now. If nobody else replies to this post till Monday, reply to this post again (so that I get an email) and I'll try to help you with the code.

HTH

 

Gunter

Posted

<?php

function tep_show_category($counter) {

   global $foo, $categories_string, $id;



   for ($a=0; $a<$foo[$counter]['level']; $a++) {

     $categories_string .= "  ";

   }



   $categories_string .= '<a href="';



   if ($foo[$counter]['parent'] == 0) {

     $cPath_new = 'cPath=' . $counter;

   } else {

     $cPath_new = 'cPath=' . $foo[$counter]['path'];

   }



   $categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new);

   $categories_string .= '">';



   if ( ($id) && (in_array($counter, $id)) ) {

     $categories_string .= '<b>';

   }



// display category name

   $categories_string .= tep_image(DIR_WS_IMAGES . $foo[$counter]['image'], $foo[$counter]['name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);



   if ( ($id) && (in_array($counter, $id)) ) {

     $categories_string .= '</b>';

   }



   if (tep_has_category_subcategories($counter)) {

     $categories_string .= '->';

   }



   $categories_string .= '</a>';



   //$categories_string .= '<br>';



   if ($foo[$counter]['next_id']) {

     tep_show_category($foo[$counter]['next_id']);

   }

 }





$categories_string = '';



 $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id, c.categories_image from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id = cd.categories_id and cd.language_id='" . $languages_id ."' order by sort_order, cd.categories_name");

 while ($categories = tep_db_fetch_array($categories_query))  {

   $foo[$categories['categories_id']] = array(

                                       'name' => $categories['categories_name'],

         'image' => $categories['categories_image'],

                                       'parent' => $categories['parent_id'],

                                       'level' => 0,

                                       'path' => $categories['categories_id'],

                                       'next_id' => false

                                      );



   if (isset($prev_id)) {

     $foo[$prev_id]['next_id'] = $categories['categories_id'];

   }



   $prev_id = $categories['categories_id'];



   if (!isset($first_element)) {

     $first_element = $categories['categories_id'];

   }

 }



 //------------------------

 if ($cPath) {

   $new_path = '';

   $id = split('_', $cPath);

   reset($id);

   while (list($key, $value) = each($id)) {

     unset($prev_id);

     unset($first_id);

     $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . $value . "' and c.categories_id = cd.categories_id and cd.language_id='" . $languages_id ."' order by sort_order, cd.categories_name");

     $category_check = tep_db_num_rows($categories_query);

     if ($category_check > 0) {

       $new_path .= $value;

       while ($row = tep_db_fetch_array($categories_query)) {

         $foo[$row['categories_id']] = array(

                                             'name' => $row['categories_name'],

                                             'parent' => $row['parent_id'],

                                             'level' => $key+1,

                                             'path' => $new_path . '_' . $row['categories_id'],

                                             'next_id' => false

                                            );



         if (isset($prev_id)) {

           $foo[$prev_id]['next_id'] = $row['categories_id'];

         }



         $prev_id = $row['categories_id'];



         if (!isset($first_id)) {

           $first_id = $row['categories_id'];

         }



         $last_id = $row['categories_id'];

       }

       $foo[$last_id]['next_id'] = $foo[$value]['next_id'];

       $foo[$value]['next_id'] = $first_id;

       $new_path .= '_';

     } else {

       break;

     }

   }

 }

 tep_show_category($first_element); 



 /*$info_box_contents = array();

 $info_box_contents[] = array('align' => 'left',

                              'text'  => $categories_string

                             );

 new infoBox($info_box_contents);*/

 echo $categories_string;

?>

 

that will list the categories, with images in a line

 

if you still have the real cattegories box active you will need to change the name of the function in the above example

 

i.e. tep_show_category could change to tep_show_category_images

 

 

you can fiddle with the html to make it look how you want

Posted

Hi gem,

 

Your site is looking really good. I have tried to do the same as your request on a previous occasion but failed with this site here:

 

http://www.tabsystems.co.uk/catalog/default.php

 

I have looked at your code and would like to try and implement it. However I am really new to php so would be so grateful if you could give me some simple instructions as to what to do e.g. a simple step by step instruction as to which files to change please.

 

If you have time I would be most grateful.

 

Many thanks

Dave

up the down escalator..........

  • 2 months later...
Posted

Thanks a lot for good contribution.

Could you help me please with one small thing:

 

How to put category name under category image?

 

Thanks in advance

Posted

There is a main_categories.php contribution which shows the main categories with links. (name and image).

 

It is in the contributions area..

 

I have installed in ms2 and works very nicely..

I just have one problem personally..

I would like to have it outside the contentbox...

 

To look just the one in the site above...

I can't get it outside without cousing an error..

if someone with knowloadge like to play around, I can post the all file here

 

Thanks

  • 6 years later...
Posted
<?php

function tep_show_category($counter) {

global $foo, $categories_string, $id;



for ($a=0; $a<$foo[$counter]['level']; $a++) {

  $categories_string .= "  ";

}



$categories_string .= '<a href="';



if ($foo[$counter]['parent'] == 0) {

  $cPath_new = 'cPath=' . $counter;

} else {

  $cPath_new = 'cPath=' . $foo[$counter]['path'];

}



$categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new);

$categories_string .= '">';



if ( ($id) && (in_array($counter, $id)) ) {

  $categories_string .= '<b>';

}



// display category name

$categories_string .= tep_image(DIR_WS_IMAGES . $foo[$counter]['image'], $foo[$counter]['name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);



if ( ($id) && (in_array($counter, $id)) ) {

  $categories_string .= '</b>';

}



if (tep_has_category_subcategories($counter)) {

  $categories_string .= '->';

}



$categories_string .= '</a>';



//$categories_string .= '<br>';



if ($foo[$counter]['next_id']) {

  tep_show_category($foo[$counter]['next_id']);

}

 }





$categories_string = '';



 $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id, c.categories_image from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id = cd.categories_id and cd.language_id='" . $languages_id ."' order by sort_order, cd.categories_name");

 while ($categories = tep_db_fetch_array($categories_query))  {

$foo[$categories['categories_id']] = array(

									'name' => $categories['categories_name'],

	  'image' => $categories['categories_image'],

									'parent' => $categories['parent_id'],

									'level' => 0,

									'path' => $categories['categories_id'],

									'next_id' => false

								   );



if (isset($prev_id)) {

  $foo[$prev_id]['next_id'] = $categories['categories_id'];

}



$prev_id = $categories['categories_id'];



if (!isset($first_element)) {

  $first_element = $categories['categories_id'];

}

 }



 //------------------------

 if ($cPath) {

$new_path = '';

$id = split('_', $cPath);

reset($id);

while (list($key, $value) = each($id)) {

  unset($prev_id);

  unset($first_id);

  $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . $value . "' and c.categories_id = cd.categories_id and cd.language_id='" . $languages_id ."' order by sort_order, cd.categories_name");

  $category_check = tep_db_num_rows($categories_query);

  if ($category_check > 0) {

	$new_path .= $value;

	while ($row = tep_db_fetch_array($categories_query)) {

	  $foo[$row['categories_id']] = array(

										  'name' => $row['categories_name'],

										  'parent' => $row['parent_id'],

										  'level' => $key+1,

										  'path' => $new_path . '_' . $row['categories_id'],

										  'next_id' => false

										 );



	  if (isset($prev_id)) {

		$foo[$prev_id]['next_id'] = $row['categories_id'];

	  }



	  $prev_id = $row['categories_id'];



	  if (!isset($first_id)) {

		$first_id = $row['categories_id'];

	  }



	  $last_id = $row['categories_id'];

	}

	$foo[$last_id]['next_id'] = $foo[$value]['next_id'];

	$foo[$value]['next_id'] = $first_id;

	$new_path .= '_';

  } else {

	break;

  }

}

 }

 tep_show_category($first_element); 



 /*$info_box_contents = array();

 $info_box_contents[] = array('align' => 'left',

						   'text'  => $categories_string

						  );

 new infoBox($info_box_contents);*/

 echo $categories_string;

?>

 

that will list the categories, with images in a line

 

if you still have the real cattegories box active you will need to change the name of the function in the above example

 

i.e. tep_show_category could change to tep_show_category_images

 

 

you can fiddle with the html to make it look how you want

 

1.The code post above doesn't work for ie8 , am i right?

2. i want to use an menu with an changing image like this <img alt="info" src="ms/category11.png" onmouseout="java script:this.src='ms/info11.png';" onmouseover="java script:this.src='ms/category2.png';" class="menu-element" border="0"></a>

 

how can i do this with this code?is it possible that the second image is shown permanently if i'm in the category?

 

ps.:sorry for my bad english

Posted
2. i want to use an menu with an changing image like this <img alt="info" src="ms/category11.png" onmouseout="java script:this.src='ms/info11.png';" onmouseover="java script:this.src='ms/category2.png';" class="menu-element" border="0"></a>
Something like

	$categories_string .= tep_image(DIR_WS_IMAGES . $foo[$counter]['image'], $foo[$counter]['name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'onmouseout="java script:this.src=\'' . DIR_WS_IMAGES . 'out/' . $foo[$counter]['image'] .'\';" onmouseover="java script:this.src=\'' . DIR_WS_IMAGES . 'over/' . $foo[$counter]['image'] . '\';" class="menu-element"');

would probably do it with the above code. Note: your HTML had three images, so I included three. It's possible that you could delete . 'out/' from the code and have it work the way that you want. It would be harder to have different names for the images (meaning that you'd have to edit more code in more files). It's easier to set it up with multiple directories. Then just use FTP to make sure that the images exist in the proper directories.

Always back up before making changes.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...