You are here:  » Image by category


Image by category

Submitted by henk on Sun, 2007-02-25 12:09 in

Hi David,

Is it possible to have category images ( like merchants images ).

Thx Henk

Submitted by support on Sun, 2007-02-25 13:42

Hi Henk,

Straight forward to do; using the same technique as merchant logo modification.

First, create a directory for the category images, for example:

images/categories/

Then, load your category images into that directory with the same file names as the categories themselves, and not using an extenstion (e.g. .gif).... for example you might then have:

images/categories/Books
images/categories/Electronics

Finally, to use the images in the code, wherever you are displaying a product (or category list) you can use the category value to see if there is a category image and display it if so. For example, in html/product.php you could use the following code:

<?php
  
if (file_exists("images/categories/".$mainProduct["category"]))
  {
    print 
"<img src='".$config_baseHREF."images/categories/".$mainProduct["category"]."' />";
  }
?>

Hope this helps!
Cheers,
David.

Submitted by henk on Mon, 2007-02-26 20:26

Thx,

I got it working with the product and now to the html/atoz file

is the code

<?php
if (file_exists("images/categories/".$product["category"]))
  {
    print 
"<img src='".$config_baseHREF."images/categories/".$product["category"]."' />";
  }
?>

but where can i place it.

Thx HEnk

Submitted by support on Mon, 2007-02-26 20:34

Hi Henk,

The existing code to display an item in html/atoz.php is line 43:

print "<p><a href='".$item["href"]."'>".$item["name"]."</a></p>";

Now, since this file is used for both merchant and brand A-Z, you need to check if you are displaying categories before checking for images with the above code.

In place of the above code, do something like this:

if ($_SERVER["PHP_SELF"] == $config_baseHREF."categories.php")
{
  // new code for categories, the image will be a link....
  if (file_exists("images/categories/".$item["name"]))
  {
    print "<a href='".$item["href"]."'>";
    print "<img border='0' src='".$config_baseHREF."images/categories/".$item["name"]."' />";
    print "</a>";
  }
  else
  {
    print "<p><a href='".$item["href"]."'>".$item["name"]."</a></p>";
  }
}
else
{
  // the original code
  print "<p><a href='".$item["href"]."'>".$item["name"]."</a></p>";
}

Hope this helps!
Cheers,
David.

Submitted by henk on Tue, 2007-02-27 20:50

Hi,

got it now without errors, but the images are not showing.

link

thx
Henk

Submitted by support on Wed, 2007-02-28 09:39

Hi Henk,

The page in your link does not have the categories URL, so the test in the code won't work. However, I went to the /categories.php link on your site and there were still no images; so it is down to one of the following tests in the new code:

if ($_SERVER["PHP_SELF"] == $config_baseHREF."categories.php")
{
  // new code for categories, the image will be a link....
  if (file_exists("images/categories/".$item["name"]))

If for testing purposes you could first change this as follows:

if (1)
{
  // new code for categories, the image will be a link....
  if (file_exists("images/categories/".$item["name"]))

This will always check for images and should fix the problem if $_SERVER["PHP_SELF"] is not set on your server. If that still doesn't work, try overriding the file exists link also; as follows:

if (1)
{
  // new code for categories, the image will be a link....
  if (1)

At this stage images should be displayed. If not, check the path to the images is valid (we can do this by looking at the IMG html that is generated by using View > Source, and comparing it to the actual path to the images).

Hope this helps,
Cheers,
David.

Submitted by Henk3001 on Wed, 2007-02-28 10:34

This is working and it takes the counting with it ( but still no images).

Thx Henk

Submitted by support on Wed, 2007-02-28 11:55

Hi Henk,

I'm not sure what is going on now - i'm not seeing the category names on your site any more.

Can you email me your:

categories.php
html/atoz.php

...and i'll make some debug changes for you to find out why it's not working.

Also, I notice your link above is not your categories page... Have you copied the code from categories.php to display categories here?

Can you also send me a link to a product page where you have got your category images being displayed correctly so that I can compare the image URLs.

Cheers,
David.

Submitted by henk on Wed, 2007-02-28 20:31

Got it, when you pullout the code for counting products the images working.

Thx Henk

Submitted by johnmcg on Tue, 2011-08-02 08:51

Hi David,

Can you provide an updated script for this that includes the merchant images in the atoz?

I tried to add this to the current (12/10B) without changing the merchant image (which I also need to display) and crashed it (blank page displays under category header).

Thanks,
John

Submitted by support on Tue, 2011-08-02 08:55

Hello John,

12/10B already includes merchant logos displayed by the A-Z html module, so to add images for categories that can now be plumbed in to categories.php. Look for the following code at line 16:

        $item["name"] = $product["category"];

...and REPLACE with:

        $item["name"] = $product["category"];
        if (file_exists("images/categories/".$product["category"]))
        {
          $item["logo"] = $config_baseHREF."images/categories/".$product["category"];
        }

Cheers,
David.
--
PriceTapestry.com

Submitted by shaunmac on Mon, 2016-02-15 18:49

What would be the code for 15/09A? I tried finding $item["name"] = $product["category"]; at line 16 but didnt see it. All I could find was $item["name"] = $category["name"];
Thanks,
Shaun

Submitted by support on Mon, 2016-02-15 19:03

Hi Shaun,

categories.php now contains separate sections for handling Category A-Z depending on whether using category hierarchy or basic feed categories, so for 15/09A look for the existing code at line 80:

        $item["name"] = $product["category"];

...and REPLACE with:

        $item["name"] = $product["category"];
        if (file_exists("images/categories/".$product["category"]))
        {
          $item["logo"] = $config_baseHREF."images/categories/".$product["category"];
        }

Cheers,
David.
--
PriceTapestry.com