Forum

Thread tagged as: Question, Shop

How to get product category from id

I'd like to display the category for a given product on its product page.

If I use product_category() I need to pass in the path but my product query returns the category ids.

What's the best way to get the path from the id?

Thanks.

Mark Smith

Mark Smith 0 points

  • 1 month ago
Drew McLellan

Drew McLellan 2591 points
Perch Support

my product query returns the category ids

Which query is that? Can you show us what you're doing?

I have a product detail page where I output my product using:-

perch_shop_product(perch_get('slug'), ['template' => 'products/product_display.html']);

I then included the <perch:showall /> tag in my product_display.html template and searched through for anything related to categories. I see an array called category which I think includes the ids of the categories attached to this product.

If I wanted to output the title or link for this category I don't know how to without using product_category() because I only have the id, not the slug.

Hussein Al Hammad

Hussein Al Hammad 86 points
Registered Developer

Hello Mark,

Are you trying to display the categories inside the product_display.html template? If so, you can use perch:categories tags to do so:

<perch:categories id="category" set="products" label="Category">
    <perch:category id="catTitle" />
</perch:categories>

Thanks Hussein, that's working for me.

I've been given the answer, how do I close this thread to stop spam?

Drew McLellan

Drew McLellan 2591 points
Perch Support

I've unsubscribed you.

I strongly applaud that beginners stay away from astrophotography until they have well-read to travel the sky. Astrophotography is by https://writemyessayguru.com far the most well-appointed and difficult area of amateur astronomy.

A product category is a type of product or service. Product categories are typically created by a firm or industry organization to organize products. This can include a hierarchy of categories that resemble a tree structure. You can also, check http://papersize.co/ for more information.

$app = JFactory::getApplication(); $menu = $app->getMenu(); if($active = $menu->getActive()){ $whichMenu = $active->alias; }else{ $whichMenu=-1; } now you can implement this query i get category page id then its going to individual details products. https://www.getmyleather.com/