Created
May 18, 2021 07:36
-
-
Save TLWebdesign/c5e16bf03e556b4d5495783ae83c555c to your computer and use it in GitHub Desktop.
Creating categories in Joomla Programmatically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$tagTitles = array( | |
"title 1", | |
"title 2", | |
"title 3" | |
); | |
foreach ($tagTitles as $title ) | |
{ | |
$category = JTable::getInstance('Category'); | |
$category->extension = "com_[[[component]]].training"; | |
$category->title = $title; | |
$category->description = ''; | |
$category->published = 1; | |
$category->access = 1; | |
$category->params = '{"target":"","image":""}'; | |
$category->metadata = '{"page_title":"","author":"","robots":""}'; | |
$category->language = '*'; | |
// Set the location in the tree | |
$category->setLocation(1, 'last-child'); | |
// Check to make sure our data is valid | |
if (!$category->check()) | |
{ | |
JError::raiseNotice(500, $category->getError()); | |
return false; | |
} | |
// Now store the category | |
if (!$category->store(true)) | |
{ | |
JError::raiseNotice(500, $category->getError()); | |
return false; | |
} | |
// Build the path for our category | |
$category->rebuildPath($category->id); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment