To create the category firstly create the category Model object through below code.
$category = Mage::getModel('catalog/category');
after that define the category name, Url key, etc.
$parentId = '2'; $category = Mage::getModel('catalog/category'); $category->setName('category_name'); $category->setUrlKey('category_key'); $category->setIsActive(1); $category->setDisplayMode('PRODUCTS'); $category->setIsAnchor(1); //for active anchor $category->setStoreId(Mage::app()->getStore()->getId()); $parentCategory = Mage::getModel('catalog/category')->load($parentId); $category->setPath($parentCategory->getPath()); $category->save();
Note:- parentId is a category id, where we create a child category of this category.