VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: bodrilo on January 25, 2013, 09:28:52 AM

Title: Parent category on a child cat page
Post by: bodrilo on January 25, 2013, 09:28:52 AM
I want to print the parent category name on a child category page

the current category name prints out like this
echo $this->category->category_name

but how do i get the parent category?
Title: Re: Parent category on a child cat page
Post by: K&K media production on January 27, 2013, 13:45:08 PM
Hi

please try this code:


$q = 'SELECT `category_parent_id` FROM `#__virtuemart_category_categories` WHERE `category_child_id`=' . $this->category->virtuemart_category_id;
$db = JFactory::getDbo();
$db->setQuery($q);
$parentCategoryID = $db->loadResult();

if ($parentCategoryID != '0') {
   $categoryModel = VmModel::getModel('category');
   $parentCategory = $categoryModel->getCategory($parentCategoryID);

   echo $parentCategory->category_name;
}



Regards,
Maik
Title: Re: Parent category on a child cat page
Post by: bodrilo on January 29, 2013, 19:56:53 PM
thank you thank you thank you  :)
Title: Re: Parent category on a child cat page
Post by: kobiavr on June 16, 2013, 12:24:58 PM
thank you kkmediaproduction
this is help me but i have a problem

i i have a deep category like:
category1 -> subcategory1 -> subcategory2

in the page of subcategory2 i get the name of subcategory1
how can i get on subcategory2 the name of category1

kobi