2017 © Pedro Peláez
 

library component-taxonomy

Taxonomy helper for WordPress

image

flexpress/component-taxonomy

Taxonomy helper for WordPress

  • Wednesday, August 20, 2014
  • by timperry
  • Repository
  • 1 Watchers
  • 0 Stars
  • 74 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

FlexPress taxonomy component

Install with Pimple

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"]
    ));
};
  • Note the dependency $c['objectStorage'] is a SPLObjectStorage

Creating a concreate Taxonomy class

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";
  }

}

Public Methods

  • getSingularName() - returns the singular name of the taxonomy.
  • getPluralName() - returns the plural name of the taxonomy.
  • getArgs() - returns the array of args.
  • getLabels() - Returns the array of labels.
  • getName() - Returns taxonomy name.
  • getSupportedPostTypes() - Return an array of post types the taxonomy should be attached to.

TaxonomyHelper usage

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)

Public methods

  • registerTaxonomies() - Registers the taxonomies provided.

The Versions

20/08 2014

dev-master

9999999-dev

Taxonomy helper for WordPress

  Sources   Download

13/08 2014

v1.0.0

1.0.0.0

Taxonomy helper for WordPress

  Sources   Download