how to get Category NAME in the Product

  • Posts: 11
  • Thank you received: 0
11 years 8 months ago #136092

-- url of the page with the problem -- : eight4eight.com/joomla/index.php/categor...-with-the-hippy-boys
-- HikaShop version -- : HikaShop Essential 2.2.2, Joomla!™ Online Store Component
-- Joomla version -- : 3.2
-- PHP version -- : 5.4
-- Browser(s) name and version -- : chrome - latest
-- Error-message(debug-mod must be tuned on) -- : Error_message

I would like to show the category before the Product Name in each product independently- regardless of if the user gets to the page by brand or category.. how can I accomplish this task? I can open the product template - but I do not know how to call out and echo the product name? Thanks in advance.

I appreciate any help in this direction..

Please Log in or Create an account to join the conversation.

  • Posts: 26264
  • Thank you received: 4043
  • MODERATOR
11 years 8 months ago #136111

Hi,

Basically, it is not really possible like that to display the category name in the product page.
The reason is simple : a product can have multiple categories. You can't know in which one you are except if you use a category list (like the breadcrumb do).

But in the product page view, you can access to " $this->categories " which is an array of the product categories.
It contains the categories object, so you can do

$first_category = reset($this->categories);
echo $first_category->category_name;
If you want to display the category name of the first category of the product.

But be careful, like I said in the beginning of the message, you can have wrong display if your product have several categories and the navigation can display the product from another category than the first product category.

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.

  • Posts: 251
  • Thank you received: 2
10 years 1 week ago #210958

Is it possible to get the last category, instead of the first?

Thank you!

Last edit: 10 years 1 week ago by Nello.

Please Log in or Create an account to join the conversation.

  • Posts: 84233
  • Thank you received: 13673
  • MODERATOR
10 years 1 week ago #210976

Hi,

Yes.
Instead of the PHP reset function you can use the end function in order to get the last one.

The following user(s) said Thank You: Nello

Please Log in or Create an account to join the conversation.

Time to create page: 0.076 seconds
Powered by Kunena Forum