Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Add Category Name to Product Listing above description

Add Category Name to Product Listing above description

Views: 4,865

Results 1 to 20 of 27
22 Sep 2008, 2:17 AM
#1
preacherman avatar

preacherman

New Zenner

Join Date:
Oct 2007
Posts:
7
Plugin Contributions:
0

Add Category Name to Product Listing above description

Is it possible to add the "Catagory Name" below the "Product's Name" on the product listing pages (right above the description)?

I assume that this can be done by adding a line of code in the Product Listing Files (such as the tpl_modules_products_new_listing.php file, etc...), however I have no idea what the code is that you would add.

Any suggestions on what code to add to the product listing files?

22 Sep 2008, 4:38 AM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Add Category Name to Product Listing above description

The easiest way is to use a function call for it:
zen_categories_lookup($categories_id)

where $categories_id would be the one you are in ... for example, on the Product Listing module you should be able to use:
zen_categories_lookup($current_category_id)

to display the current categories_name ...

22 Sep 2008, 4:44 AM
#3
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Add Category Name to Product Listing above description

For files where you do not know the categories_id, you could use:
zen_categories_lookup(zen_products_lookup($products_new->fields['products_id'], 'master_categories_id'))

Where the one function looks up the categories_name from the master_categories_id of the product ...

22 Sep 2008, 10:31 PM
#4
preacherman avatar

preacherman

New Zenner

Join Date:
Oct 2007
Posts:
7
Plugin Contributions:
0

Re: Add Category Name to Product Listing above description

Linda,

Thanks for the fast reply… YOU ARE AWESOME! Your posts have been a huge help to me on this forum!

I hate to be a pain, but I could use a little more help on this – I just don’t know anything about code (I barely know enough to figure out which files produce the code that makes the product listings).

Would it be possible for you to show me what code to put on which lines (maybe using the Product Listing Module as an example)? And then I can change it on the other files from your example.

Thanks for any assistance you can give!

23 Sep 2008, 1:59 AM
#5
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Add Category Name to Product Listing above description

On the New Products Listing you can:

Try copying the file:
/includes/templates/templates_default/templates/tpl_modules_products_new_listing.php

to your templates and overrides directory:
/includes/templates/your_template_dir/templates/tpl_modules_products_new_listing.php

and edit it and change:

      if (PRODUCT_NEW_LIST_NAME != '0') {
        $display_products_name = '<a href="' . zen_href_link(zen_get_info_page($products_new->fields['products_id']), 'cPath=' . zen_get_generated_category_path_rev($products_new->fields['master_categories_id']) . '&products_id=' . $products_new->fields['products_id']) . '"><strong>' . $products_new->fields['products_name'] . '</strong></a>' . str_repeat('<br clear="all" />', substr(PRODUCT_NEW_LIST_NAME, 3, 1));

to read:

      if (PRODUCT_NEW_LIST_NAME != '0') {
//        $display_products_name = '<a href="' . zen_href_link(zen_get_info_page($products_new->fields['products_id']), 'cPath=' . zen_get_generated_category_path_rev($products_new->fields['master_categories_id']) . '&products_id=' . $products_new->fields['products_id']) . '"><strong>' . $products_new->fields['products_name'] . '</strong></a>' . str_repeat('<br clear="all" />', substr(PRODUCT_NEW_LIST_NAME, 3, 1));
        $show_cat_name = zen_categories_lookup(zen_products_lookup($products_new->fields['products_id'], 'master_categories_id'));
        $display_products_name = '<a href="' . zen_href_link(zen_get_info_page($products_new->fields['products_id']), 'cPath=' . zen_get_generated_category_path_rev($products_new->fields['master_categories_id']) . '&products_id=' . $products_new->fields['products_id']) . '"><strong>' . $products_new->fields['products_name'] . '</strong></a>' . '<br>cat: ' . $show_cat_name . str_repeat('<br clear="all" />', substr(PRODUCT_NEW_LIST_NAME, 3, 1));

On the Product Listing you can copy the module:
/includes/modules/products_listing.php

to your templates and overrides directory:
/includes/modules/your_template_dir/products_listing.php

and change:

        if (isset($_GET['manufacturers_id'])) {
          $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ?  zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>' ;
        } else {
          $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ?  zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>';
        }

to read:

        $show_cat_name = zen_categories_lookup(zen_products_lookup($listing->fields['products_id'], 'master_categories_id'));
        if (isset($_GET['manufacturers_id'])) {
          $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ?  zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '<br />Cat: ' . $show_cat_name . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>' ;
        } else {
          $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ?  zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '<br />Cat: ' . $show_cat_name . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>';
        }
23 Sep 2008, 6:47 PM
#6
preacherman avatar

preacherman

New Zenner

Join Date:
Oct 2007
Posts:
7
Plugin Contributions:
0

Re: Add Category Name to Product Listing above description

Thanks Linda!

Works like a charm!:clap:

I really appreciate it! Thank you SO MUCH!

24 Sep 2008, 1:20 AM
#7
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Add Category Name to Product Listing above description

Glad that this could get your back on track ... thanks for the update ... :smile:

28 Nov 2008, 12:45 PM
#8
maxidvd avatar

maxidvd

New Zenner

Join Date:
Nov 2008
Location:
Jervis Bay, NSW Australi
Posts:
16
Plugin Contributions:
0

Re: Add Category Name to Product Listing above description

Ajeh:

For files where you do not know the categories_id, you could use:
zen_categories_lookup(zen_products_lookup($products_new->fields['products_id'], 'master_categories_id'))

Where the one function looks up the categories_name from the master_categories_id of the product ...

Hi Linda,

How would this work on the shopping cart page? there is no product id or cPath id to work with - I wish for my product description links in the shopping cart to link back to the main categorie and not directly back to the product - I tried too many hours to figure out a method for this and I cant, I dont know how to call the product id - the varibles in the shopping cart page confused me too much - now im tired.

there must be away, my site operates on a very different format from most sites and I am using categories like a mother product for a family of linked products - I cant really explain how it works but I will show case this site when Im done, and will release the template minus a few copyrighted logos & images back to the Zen community in a few weeks.

Cheers Lee.

28 Nov 2008, 6:48 PM
#9
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Add Category Name to Product Listing above description

For the shopping_cart see if using for the products_id if:
$product['id']

works better for you to obtain the master_categories_id of the product ...

28 Nov 2008, 11:18 PM
#10
maxidvd avatar

maxidvd

New Zenner

Join Date:
Nov 2008
Location:
Jervis Bay, NSW Australi
Posts:
16
Plugin Contributions:
0

Re: Add Category Name to Product Listing above description

Ajeh:

For the shopping_cart see if using for the products_id if:
$product['id']

works better for you to obtain the master_categories_id of the product ...

Yes it done the job, thank you Linda.

I then tried to create a new function that returned the products category_id from the products_id (I managed to dig up some relevant old code from a post you done on the osComerce forum:

zen_get_products_category_id($products_id)

and it kept braking the site, stupid me = turns out this function already existed in Zen Cart.... thats why the function would not work.

I still dont know which file the actual function is located in, I assumed it would have been in the functions_categories.php file?

I dont want to change it, its works just the way I need it too.

does the Zen Cart Wiki explain what functions are available too use when customizing a store and a brief run down of what they do?

28 Nov 2008, 11:21 PM
#11
maxidvd avatar

maxidvd

New Zenner

Join Date:
Nov 2008
Location:
Jervis Bay, NSW Australi
Posts:
16
Plugin Contributions:
0

Re: Add Category Name to Product Listing above description

In Answer to my last question:

About the WIKI Docs

Control Structures
Function Calls
Function Definitions
Comments

http://www.zen-cart.com/wiki/index.php/Developers_Standards

only its empty, I guess its a work in progress.

28 Nov 2008, 11:31 PM
#12
maxidvd avatar

maxidvd

New Zenner

Join Date:
Nov 2008
Location:
Jervis Bay, NSW Australi
Posts:
16
Plugin Contributions:
0

Re: Add Category Name to Product Listing above description

Well I was going to be a good samaratin and enter the details of this function to get the Wiki rolling but it wont let me register to edit its pages.

Call the current categories id from the products id:

<?php echo zen_get_products_category_id($product['id']);?>

Needs to be on a page or in a array that knows the products_id.

28 Nov 2008, 11:39 PM
#13
maxidvd avatar

maxidvd

New Zenner

Join Date:
Nov 2008
Location:
Jervis Bay, NSW Australi
Posts:
16
Plugin Contributions:
0

Re: Add Category Name to Product Listing above description

Call the current categories id from the products id:

<?php echo zen_get_products_category_id($product['id']); ?>

Needs to be on a page or in a array that knows the products_id.

1 Dec 2008, 11:29 PM
#14
eljay avatar

eljay

New Zenner

Join Date:
Nov 2008
Posts:
9
Plugin Contributions:
0

Re: Add Category Name to Product Listing above description

I would like to show only the description and not the product name in the listing. I found a thread that talks about this but does not have any instructions on how to do it.
https://www.zen-cart.com/forum/showthread.php?p=285189

I am not all that great in PHP, I would appreciate any help.

2 Dec 2008, 12:27 AM
#15
maxidvd avatar

maxidvd

New Zenner

Join Date:
Nov 2008
Location:
Jervis Bay, NSW Australi
Posts:
16
Plugin Contributions:
0

Re: Add Category Name to Product Listing above description

Hi Eljay

In folder: zencart\includes\modules

Create a new folder in there and name it exactly the same as your current template folder.

If your using the CLASSIC template it would be this:
zencart\includes\modules\CLASSIC without the capitals of course.

Now go back to the zencart\includes\modules folder and find the file: product_listing.php

And copy that file to you new folder:

zencart\includes\modules\CLASSIC\product_listing.php

Now that its copied into the new "Template Overide Folder" you need to edit the code with a text editing program like windows notepad.. or Winsyntax

and search for ir browse lines 95 to 102 you will find this code snippet

case 'PRODUCT_LIST_NAME':
blah blah blah blah
blah blah blah blah
blah blah blah blah
}
break;

use the code below and copy over it, this will remove then product name but leave the description intack.

/*
        case 'PRODUCT_LIST_NAME':
        $lc_align = '';
        if (isset($_GET['manufacturers_id'])) {
          $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ?  zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>' ;
        } else {
          $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ?  zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>';
        }
        break;
*/

        case 'PRODUCT_LIST_NAME':
        $lc_align = '';
        if (isset($_GET['manufacturers_id'])) {
          $lc_text = '<div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>' ;
        } else {
          $lc_text = '<div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>';
        }
        break;

Sounds like a lot of work, but its better to do it right using the template override system then to just go in and hack a system
file that will make your site harder to update in the future.
Cheers Lee

2 Dec 2008, 4:08 PM
#16
eljay avatar

eljay

New Zenner

Join Date:
Nov 2008
Posts:
9
Plugin Contributions:
0

Re: Add Category Name to Product Listing above description

maxidvd:

Hi Eljay

In folder: zencart\includes\modules

Create a new folder in there and name it exactly the same as your current template folder.

If your using the CLASSIC template it would be this:
zencart\includes\modules\CLASSIC without the capitals of course.
.....................

Lee, thanks for your help. I will give it a try and see how it comes out and let you know :D

16 May 2011, 6:26 AM
#17
ev8321 avatar

ev8321

New Zenner

Join Date:
May 2011
Posts:
10
Plugin Contributions:
0

Re: Add Category Name to Product Listing above description

Ajeh:

For the shopping_cart see if using for the products_id if:
$product['id']

works better for you to obtain the master_categories_id of the product ...

Hi Guys,

I know this is an extremely old post but I have been stuck on this all afternoon - hopefully someone can shed some more light on this issue. Not sure if you are still around Linda...

I am looking to display the category name of each item on the shopping cart page. I have followed suggestions found here and I know this is a peculiar issue. I have been able to display master_categories_id and one would assume that displaying a name instead of the id is possible on the shopping cart page.
I just cannot figure this one out.

Linda you have been a wonderful help in this post. Thank you very much if you do happen to fly by.

Any help or suggestions would be greatly appreciated.

P.s. I am currently running the latest version of Zen Cart.

Regards,
Evan

16 May 2011, 1:19 PM
#18
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Add Category Name to Product Listing above description

If you have the master_categories_id, you can use the function zen_get_categories_name to display the name ...

16 May 2011, 11:21 PM
#19
ev8321 avatar

ev8321

New Zenner

Join Date:
May 2011
Posts:
10
Plugin Contributions:
0

Re: Add Category Name to Product Listing above description

Ajeh:

If you have the master_categories_id, you can use the function zen_get_categories_name to display the name ...

Thanks for your swift reply.
My beginners knowledge of php is certainly not helping me out.

Could you please tell me if I am even on the right track with something like - currently not working

echo zen_get_categories_name($product['id'], 'master_categories_id');

This is what I am using to display the master_catergoried_id and it is working perfectly:

echo zen_products_lookup($product['id'], 'master_categories_id');

Currently working in file tpl_shopping_cart_default.php

THanks :)

17 May 2011, 12:36 AM
#20
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Add Category Name to Product Listing above description

You cut out the function in the second function ... try this:

echo zen_get_categories_name(zen_products_lookup($product['id'], 'master_categories_id'));