VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: SoTrue on August 06, 2018, 14:47:53 PM

Title: Call Child Category through PHP
Post by: SoTrue on August 06, 2018, 14:47:53 PM
Hi Guys,

I am trying to add the category and child category programmatically, but am not sure of the variable for the child category. I have the code below, however after .$category->category_name I would then like to add the subcategory name if it is a sub category and if there is no subcategory remove the .$category->category_name completely.

$document->setTitle("Buy Womens and Mens Clothing".$category->category_name);
if ($this->app->getCfg('MetaTitle') == '1') {
$document->setMetaData('title',  $title);
}


Can any one advise how i can achieve this?

Best Regards
Donna
Title: Re: Call Child Category through PHP
Post by: GJC Web Design on August 06, 2018, 17:28:58 PM
you can have multiple child cats

you can do something like

$html_title = "Buy Womens and Mens Clothing ".$category->category_name;

if ($this->category->haschildren) {

foreach ( $this->category->children as $subcategory ) {
    $html_title = $html_title.' '.$subcategory->->category_name
}

}

$document->setTitle($html_title);