VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: roman5527 on April 14, 2021, 21:45:08 PM

Title: Back to parent category
Post by: roman5527 on April 14, 2021, 21:45:08 PM
Hi, can I add link on category page - back to parent category page ?

example from level 3 child category to level 2 category and .....

thanks .
Title: Re: Back to parent category
Post by: pinochico on April 14, 2021, 22:57:56 PM
What is about the question?

Quotecan I

Answer: Of course, you can.

But I think you want code for this, isn't?
Then the right question is:

"Can anyone write me the exact code I have to put on the web and where, if I want to add a link to the parent category to the category view?"

BTW - this link exists in the BreadCrumbs module, therefore this module is added to the view category of the eshop.
Title: Re: Back to parent category
Post by: roman5527 on April 15, 2021, 21:48:14 PM
Yes, you're right . My question was asked wrongly.
So I ask again.
Can anyone help me with the code to display the link back to the parent category in the category view? well thank you
Title: Re: Back to parent category
Post by: ksfbjoern on March 23, 2022, 13:30:06 PM
Hello together,

i got basicly the same question as roman5527. Has anybody a code to implement to get a separate button "Back to parent category" in a subcategory or is a button like that eventually already integrated in virtuemart, like the back to category button in the product details? That this link is existing in the breadcrumb is quit not bad, but for a non coder it is hard to extract to work only with virtuemart categorys (for example this button should not be shown in a parent category/when there is no category above).

I would be very happy about any help or tips

best regards
Title: Re: Back to parent category
Post by: Jumbo! on March 23, 2022, 16:36:54 PM
You can use the following codes in category page layout override, i.e. templates/YOUR-TEMPLATE/html/com_virtuemart/category/default.php

<?php
if (!empty($this->category))
{
$categoryModel  VmModel::getModel('Category');
$parentCategory $categoryModel->getParentCategory($this->category->virtuemart_category_id);

if (!empty($parentCategory) && !empty($parentCategory->virtuemart_category_id))
{
echo 'Go back to : <a href="' JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id=' $parentCategory->virtuemart_category_id) . '">' $parentCategory->category_name '</a>';
}
}
?>
Title: Re: Back to parent category
Post by: ksfbjoern on March 24, 2022, 10:30:46 AM
Just perfect Jumbo!

Thank you very much, that is exactly what i was looking for.

Best regard
Title: Re: Back to parent category
Post by: Jumbo! on March 24, 2022, 11:41:08 AM
You are welcome.