Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

category headings replaced with images?


wildchief

Recommended Posts

Posted

Dear Forum,

 

I have a question about the categories box. I would like to replace the top level category with an image. I have managed it to an extent (if you click on it you will be presented with the list of available sub categories but not under the image). I wondered if it was possible to do this. I have a demo of what i am talking about if you have the time to look. www.prettyposhpets.co.uk . the categories box works fine (as you would expect!) but my images cat products and dog products (which stand out more) do not create the subcategory listing (as i have no idea how to do this). My goal is to have the images replace the categories box but provide the same or similar functionality.

 

I hope this makes some sense!

 

Thank you

 

david

Posted

Hi Jason,

 

Thank you for replying, yes pretty much that. I would like my images to be at top level categories , for example my top level category is cats so I would like that to be an image. then when i click on it i would like that to display the drop down subcategories list in much the same way as it does as standard but my top level categories should be images.

 

Does this make sense?

 

www.prettyposhpets.co.uk for a demo of the top level images I would like to replace the text only top level category headings half working!

 

Thank you

Posted

you have to create images that match your category IDs. So for example if one of your categories is cPath=21 then create an image called 21.gif. Then instead of writing out the category name and number in /catalog/includes/boxes/categories.php, stick an image tag in there and write out the number. So replace this:

 

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

 

with this:

 

$categories_string .= tep_image(DIR_WS_IMAGES . 'navigation/' . $counter . '.gif');

 

In this case I put the nav images in a /navigation/ folder within the images directory.

Posted
you have to create images that match your category IDs. So for example if one of your categories is cPath=21 then create an image called 21.gif. Then instead of writing out the category name and number in /catalog/includes/boxes/categories.php, stick an image tag in there and write out the number. So replace this:

 

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

 

with this:

 

$categories_string .= tep_image(DIR_WS_IMAGES . 'navigation/' . $counter . '.gif');

 

In this case I put the nav images in a /navigation/ folder within the images directory.

 

Hi Jason,

 

Thank you for helping. That was a very consise fix! I have got it working how I had hoped

www.prettyposhpets.co.uk.

 

Thank you

Posted
Hi Jason,

 

Thank you for helping. That was a very consise fix! I have got it working how I had hoped

www.prettyposhpets.co.uk.

 

Thank you

 

Hi All

 

This fix worked great, but how do i get the subcategory to still come up as text like on your site? my site (www.phoenix-games.co.uk) is looking for images.

 

Thanks in advance

 

Chris

Posted
Hi All

 

This fix worked great, but how do i get the subcategory to still come up as text like on your site? my site (www.phoenix-games.co.uk) is looking for images.

 

Thanks in advance

 

Chris

 

Hi Chris,

 

I actually did not use the above methods I ended up using this contribution instead http://www.oscommerce.com/community/contri...,category+image

 

If you look at the supplied screen shot within the aforementioned contribution package it looks as though it also displays the sub category image which is not what I wanted (nor do you as I understand it) but if you dig a little deeper you will see there is an option which lets you have the JUST the top level category images (like my site www.prettyposhpets.co.uk -sorry its down at the mo). That was exactly what i wanted.

 

I used this option

 

categories_main_images.php -- This gives main category images only. Which to my frustration did not work on my site and the others did. However I fxed it and here it is:

Replace YOUR categories.php with this one pasted below (backing up it up first of course! And bear in mind that you may already have some changes if you have used other contributions)

 

<?php

/*

$Id: categories.php,v 1.25 2003/07/09 01:13:58 hpdl Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

*/

 

function tep_show_category($counter) {

global $tree, $categories_string, $cPath_array;

 

for ($i=0; $i<$tree[$counter]['level']; $i++) {

$categories_string .= "  ";

}

 

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

 

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

$cPath_new = 'cPath=' . $counter;

} else {

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

}

 

$categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">';

 

if (isset($cPath_array) && in_array($counter, $cPath_array)) {

$categories_string .= '<b>';

}

 

// display category name

if (tep_not_null($tree[$counter]['image'])) {

$categories_string .= tep_image(DIR_WS_IMAGES . $tree[$counter]['image'], $tree[$counter]['name'], '162', '44') ;

}else{

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

}

if (isset($cPath_array) && in_array($counter, $cPath_array)) {

$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 ($tree[$counter]['next_id'] != false) {

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

}

}

?>

<!-- categories //-->

<tr>

<td>

<?php

$info_box_contents = array();

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

 

new infoBoxHeading($info_box_contents, true, false);

 

$categories_string = '';

$tree = array();

 

$categories_query = tep_db_query("select c.categories_id, c.categories_image, 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='" . (int)$languages_id ."' order by sort_order, cd.categories_name");

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

$tree[$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($parent_id)) {

$tree[$parent_id]['next_id'] = $categories['categories_id'];

}

 

$parent_id = $categories['categories_id'];

 

if (!isset($first_element)) {

$first_element = $categories['categories_id'];

}

}

 

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

if (tep_not_null($cPath)) {

$new_path = '';

reset($cPath_array);

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

unset($parent_id);

unset($first_id);

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

if (tep_db_num_rows($categories_query)) {

$new_path .= $value;

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

$tree[$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($parent_id)) {

$tree[$parent_id]['next_id'] = $row['categories_id'];

}

 

$parent_id = $row['categories_id'];

 

if (!isset($first_id)) {

$first_id = $row['categories_id'];

}

 

$last_id = $row['categories_id'];

}

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

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

$new_path .= '_';

} else {

break;

}

}

}

tep_show_category($first_element);

 

$info_box_contents = array();

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

 

new infoBox($info_box_contents);

?>

</td>

</tr>

<!-- categories_eof //-->

  • 2 weeks later...
Posted
Works Great thanks a lot!!

 

Chris

phoenix-games.co.uk

 

great

Archived

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

×
×
  • Create New...