- Posts: 28
- Thank you received: 0
Show product's category name in product listing
9 years 1 month ago #275953
by ashx88
Show product's category name in product listing was created by ashx88
Hi,
I would like to show each product's category name in the product listing page. What is the code that displays the category name?
Thanks!
I would like to show each product's category name in the product listing page. What is the code that displays the category name?
Thanks!
Please Log in or Create an account to join the conversation.
9 years 1 month ago #275973
by Jerome
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
Replied by Jerome on topic Show product's category name in product listing
Hello,
When you create a post in our forum ; please fill the requested elements so our support team will have the required knowledge to be able to answer you with more accuracy.
Thank you for your understanding.
About your request, without knowing your website, the context and the HikaShop version number you're using ; I'm afraid that I can't answer you.
Regards,
When you create a post in our forum ; please fill the requested elements so our support team will have the required knowledge to be able to answer you with more accuracy.
Thank you for your understanding.
About your request, without knowing your website, the context and the HikaShop version number you're using ; I'm afraid that I can't answer you.
Regards,
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
Please Log in or Create an account to join the conversation.
Less
More
- Posts: 12953
- Thank you received: 1778
9 years 1 month ago #276466
by Mohamed Thelji
Replied by Mohamed Thelji on topic Show product's category name in product listing
Hello,
I think that you created a new thread to give us more information about what you wanted to do but I erased it by mistake, my bad.
There is no option to display the categories of a product on the listing since usually you have only one category and a listing of products already bases itself on that category to display the products listing so you already know the category of all the products of the listing and they usually are the same.
So you'll indeed need to edit the view file which displays each product in order to load its categories and then display them.
First, to know which view file you need to edit and how you can edit it, I would recommend that you read this:
www.hikashop.com/support/documentation/1...-display.html#layout
After that, if you're a developer, you should easily find how to get the product_id of the current product, run a MySQL query to load the categories of the product from the database and display that.
I would like to show each product's category name in the product listing page. What is the code that displays the category name?
I think that you created a new thread to give us more information about what you wanted to do but I erased it by mistake, my bad.
There is no option to display the categories of a product on the listing since usually you have only one category and a listing of products already bases itself on that category to display the products listing so you already know the category of all the products of the listing and they usually are the same.
So you'll indeed need to edit the view file which displays each product in order to load its categories and then display them.
First, to know which view file you need to edit and how you can edit it, I would recommend that you read this:
www.hikashop.com/support/documentation/1...-display.html#layout
After that, if you're a developer, you should easily find how to get the product_id of the current product, run a MySQL query to load the categories of the product from the database and display that.
Please Log in or Create an account to join the conversation.
9 years 1 month ago #276537
by ashx88
Replied by ashx88 on topic Show product's category name in product listing
Hi,
Thanks for getting back. Previously I enquired on how to display branding of the product at the listing page and was told to add some codes to the listing_img_title view. ( here ) Would it be as simple as that? (Are there pre-written codes that I can just copy and paste to the view file)
Unfortunately, I'm not a developer and do not know how to run a MySQL query or write the codes, they are too complex for me. Would you be able to point me in the right direction? If not, do you do paid customization?
Thanks for getting back. Previously I enquired on how to display branding of the product at the listing page and was told to add some codes to the listing_img_title view. ( here ) Would it be as simple as that? (Are there pre-written codes that I can just copy and paste to the view file)
Unfortunately, I'm not a developer and do not know how to run a MySQL query or write the codes, they are too complex for me. Would you be able to point me in the right direction? If not, do you do paid customization?
Please Log in or Create an account to join the conversation.
9 years 1 month ago - 9 years 1 month ago #276592
by kyratn
Replied by kyratn on topic Show product's category name in product listing
Hi,
This should do the job:
This will display max 2 categories of the product.
If your product is in more then 2 categories then you will have to modify numbers in this line:
You can add code above based on product view you are using. As example product/listing_img_title
Hope that helps
Kind Regards
This should do the job:
Code:
<div class="clearfix related-categories-list">
<?php
$q = 'SELECT c.* '.
' FROM ' . hikashop_table('product_category').' as pc '.
' INNER JOIN '.hikashop_table('category').' AS c ON pc.category_id = c.category_id '.
' WHERE pc.product_id = '.$this->row->product_id;
$database->setQuery($q);
$product_categories = $database->loadObjectList();
$categories = array();
if($product_categories) foreach ($product_categories as $category) $categories[] = $category->category_name;
if(count($categories) > 2) $categories = array_splice($categories, 0, 2);
foreach($categories as $k=>$c){if($k==count($categories)-1) echo '<span class="pull-left margin-reset">'.$c.'</span>'; else echo '<span class="pull-left margin-reset">'.$c.',</span>';}
?>
</div>
This will display max 2 categories of the product.
If your product is in more then 2 categories then you will have to modify numbers in this line:
Code:
if(count($categories) > 2) $categories = array_splice($categories, 0, 2);
You can add code above based on product view you are using. As example product/listing_img_title
Hope that helps
Kind Regards
Last edit: 9 years 1 month ago by kyratn.
The following user(s) said Thank You: Philip
Please Log in or Create an account to join the conversation.
9 years 1 month ago #276549
by nicolas
Replied by nicolas on topic Show product's category name in product listing
Hi,
Well, there is no "pre written" code but the code isn't that complex to write. It will require loading the categories of the product and then echoing it in the view file.
A 3rd party developer should be able to add that for you for a small price if necessary.
You can for example contact our partners:
www.hikashop.com/home/our-partners.html
Well, there is no "pre written" code but the code isn't that complex to write. It will require loading the categories of the product and then echoing it in the view file.
A 3rd party developer should be able to add that for you for a small price if necessary.
You can for example contact our partners:
www.hikashop.com/home/our-partners.html
Please Log in or Create an account to join the conversation.
Time to create page: 0.243 seconds