List current category in product listing

  • Posts: 35
  • Thank you received: 0
12 years 10 months ago #40917

I am trying to list the current category that the product is in under the Product title in the product details view (product/show.php).
My products are in a parent category, as well as child category, but it only needs to show the child category that is is located in.

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

  • Posts: 83103
  • Thank you received: 13416
  • MODERATOR
12 years 10 months ago #41054

You would first have to run a query to know the category name of the product and then display it.

But if you don't mind having the parent category name too, you could simply use the breadcrumb module of joomla. That would display the categories of the product automatically.

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

  • Posts: 35
  • Thank you received: 0
12 years 10 months ago #41748

What bit of query code gets me the child category of the product? That would be preferred over the breadcrumb mod becuase if you find the item via its parent category (has all sub elements shown), the breadcrumb doesn't show the child cat that the item item is in, and that is really what I want to list.

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

  • Posts: 83103
  • Thank you received: 13416
  • MODERATOR
12 years 10 months ago #41874

You can do like that:

$category = reset($this->categories);
echo $category->category_name;

The following user(s) said Thank You: austio

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

  • Posts: 35
  • Thank you received: 0
12 years 10 months ago #41934

Thanks! Your code did exactly what I wanted! I discovered I didn't need to have items in both the parent category and a child category with "all sub elements" shown option, which is another plus!

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

Time to create page: 0.051 seconds
Powered by Kunena Forum