-
Notifications
You must be signed in to change notification settings - Fork 17
Post Types and Taxonomies
ookhrimenko edited this page Jan 17, 2018
·
3 revisions
You can find a detailed documentation on Post type and Taxonomy components in Theme Framework documentation:
To register a new Custom Post Type, you need to define a class, extended from Framework Post_Type:
<?php
namespace Boilerplate\Theme\Post_Type;
use Boilerplate\Theme\Taxonomy\Department;
use JustCoded\WP\Framework\Objects\Post_Type;
class Employee extends Post_Type {
/**
* ID
*
* @var string
*/
public static $ID = 'employee';
/**
* Rewrite URL part
*
* @var string
*/
public static $SLUG = 'employee';
/**
* Registration function
*/
public function init() {
$this->label_singular = 'Employee';
$this->label_multiple = 'Employees';
$this->textdomain = 'boilerplate';
$this->has_single = true;
$this->is_searchable = true;
$this->rewrite_singular = false;
$this->is_hierarchical = false;
$this->admin_menu_pos = 25;
$this->admin_menu_icon = 'dashicons-format-gallery';
$this->taxonomies = array(
Department::$ID,
);
$this->register();
}
}
After that you need to create an instance of this class inside Theme::register_post_types()
method:
<?php
namespace Boilerplate\Theme;
use Boilerplate\Theme\Post_Type\Employee;
class Theme extends \JustCoded\WP\Framework\Theme {
// ...
/**
* Register post types
*/
public function register_post_types() {
Employee::instance();
}
}
To register a new Taxonomy, you need to define a new class, extended from the Framework Taxonomy:
<?php
namespace Boilerplate\Theme\Taxonomy;
use JustCoded\WP\Framework\Objects\Taxonomy;
use Boilerplate\Theme\Post_Type\Employee;
class Department extends Taxonomy {
/**
* ID
*
* @var string
*/
public static $ID = 'department';
/**
* Rewrite URL part
*
* @var string
*/
public static $SLUG = 'department';
/**
* Registration function
*/
public function init() {
$this->label_singular = 'Department';
$this->label_multiple = 'Departments';
$this->textdomain = 'boilerplate';
$this->is_hierarchical = false;
$this->has_single = true;
$this->rewrite_singular = false;
$this->has_admin_menu = true;
$this->post_types = array(
Employee::$ID,
);
$this->register();
}
}
After that you need to create an instance of this class inside Theme::register_post_types()
method:
<?php
namespace Boilerplate\Theme;
use Boilerplate\Theme\Post_Type\Employee;
/**
* Theme main entry point
*
* Theme setup functions, assets, post types, taxonomies declarations
*/
class Theme extends \JustCoded\WP\Framework\Theme {
// ...
/**
* Register post types
*/
public function register_taxonomies() {
Department::instance();
}
}
Next: Theme Options Page