Wallogit.com
2017 © Pedro Peláez
Taxonomy helper for WordPress
The taxonomy component uses two classes: - AbstractTaxonommy, which you extend to create a taxonomy. - TaxonomyHelper, which hooks into everything for you and registers the taxonomies., (*1)
Lets create a pimple config for both of these, (*2)
$pimple["documentTypeTaxonomy"] = function () {
return new DocumentType();
};
$pimple['taxonomyHelper'] = function ($c) {
return new TaxonomyHelper($c['objectStorage'], array(
$c["documentTypeTaxonomy"]
));
};
Create a concreate class that implements the AbstractTaxonomy class and implements the getName() and getSupportedPostTypes() methods., (*3)
class DocumentType extends AbstractTaxonomy {
public function getName()
{
return "document-type";
}
public function getSupportedPostTypes()
{
return array("document");
}
}
This above example is the bare minimum you must implement, the example that follows is the other extreme implementing all available methods., (*4)
class DocumentType extends AbstractTaxonomy {
public function getName()
{
return "document-type";
}
public function getSupportedPostTypes()
{
return array("document");
}
protected function getLabels()
{
$labels = parent::getLabels();
$labels['menu_name'] = 'Type';
return $labels;
}
public function getArgs()
{
$args = parent::getArgs();
$args['query_var'] = false;
return $args;
}
public function getPluralName()
{
return "Doc types";
}
public function getSingularName()
{
return "Doc type";
}
}
Once you have setup the pimple config you are use the TaxonomyHelper like this, (*5)
$helper = $pimple['taxonomyHelper']; $helper->registerTaxonomies();
That's it, the helper will then add all the needed hooks and register all the taxonomies you have provided it., (*6)