There are many types of content in Juzaweb CMS. These content types are normally described as Post Types, which may be a little confusing since it refers to all different types of content in Juzaweb CMS. For example, a post is a specific Post Type, and so is a page.
posts
)pages
)To Register custom post type to your plugin, you can use registerPostType
in Facade HookAction
. To make sure it works, add them to the action juzaweb.init
.
HookAction::registerPostType($postType, $args);
'thumbnail'
, 'comment'
namespace Juzaweb\Example\Actions;
use Juzaweb\CMS\Abstracts\Action;
class ExampleAction extends Action
{
/**
* Execute the actions.
*
* @return void
*/
public function handle(): void
{
// Add your action
$this->addAction(Action::INIT_ACTION, [$this, 'registerPostTypes']);
}
public function registerPostTypes()
{
$this->hookAction->registerPostType(
'examples',
[
'label' => trans('example Post'),
'description' => trans('This is Example Post'),
'menu_icon' => 'fa fa-list',
'supports' => ['category', 'tag'],
'metas' => [
'example' => [
'type' => 'text',
'label' => trans('Example Field')
],
'select' => [
'type' => 'select',
'label' => trans('Example Select'),
'data' => [
'options' => [
0 => trans('Disabled'),
1 => trans('Enabled')
]
]
]
],
]
);
}
}
A simple function for creating or modifying a taxonomy object based on the parameters given.
HookAction::registerTaxonomy(string $taxonomy, array|string $postType, array|string $args = array());
Example:
$this->hookAction->registerTaxonomy(
'countries',
'examples',
[
'label' => __('Countries'),
'supports' => []
]
);
Register Taxonomy with multiple Post Type
$this->hookAction->registerTaxonomy(
'countries',
['examples', 'movies'],
[
'label' => __('Countries'),
'supports' => []
]
);
namespace Juzaweb\Example\Actions;
use Juzaweb\CMS\Abstracts\Action;
class ExampleAction extends Action
{
/**
* Execute the actions.
*
* @return void
*/
public function handle(): void
{
// Add your action
$this->addAction(Action::INIT_ACTION, [$this, 'registerPostTypes']);
}
public function registerPostTypes()
{
$this->hookAction->registerPostType(
'examples',
[
'label' => __('Example Post'),
'menu_icon' => 'fa fa-list',
'supports' => ['category', 'tag'],
'metas' => [
'example' => [
'type' => 'text',
'label' => __('Example Field')
],
'select' => [
'type' => 'select',
'label' => __('Example Select'),
'data' => [
'options' => [
0 => __('Disabled'),
1 => __('Enabled')
]
]
]
],
]
);
$this->hookAction->registerTaxonomy(
'countries',
'examples',
[
'label' => __('Countries'),
'supports' => []
]
);
// Or Register Taxonomy with multiple Post Type
$this->hookAction->registerTaxonomy(
'countries',
['examples', 'movies'],
[
'label' => __('Countries'),
'supports' => []
]
);
}
}