Skip to content

gillchristian/CPT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 

Repository files navigation

CPT PRs Welcome

Helper classes to create Custom Pots Types and Taxonomies in WordPress.

I use Inflector class to capitalize and pluralize the CPT name.

how to use it

Make sure to include the source folder in your theme's folder. On your functions file include_once or require_once the cpt.inc.php file, it will load all the required files.

include_once 'CPT/src/cpt.inc.php';

##post types

###register To add a post type use the PostType class. The example below creates a custom post type called Book.

$book = new PostType('book');
$book->register();

###unregister

$book->unregister();

###adding more options setArgs($options) and setLabels($options) receive a relational array of options to customize the custom post type declaration.

In the example we make the Book custom post type private and change its menu icon.

$book->setArgs(array(
     'menu_icon' => 'dashicons-book-alt',
     'public'    => false
    ));

For more information about the custom post type register options go to the WordPress Codex.

here are some more icons, from the WordPress icons font, you can use to customize the menu icon of the custom post type.


##taxonomies

###add a taxonomy

To add a taxonomy use the Taxonomy class. The example below creates a Writer tag-like (not hierarchical) Taxonomy and a Genre category-like (hierarchical) Taxonomy. And binds them to the book Post Type we already created.

$writer = new Taxonomy('writer');

$writer->register('book');

$genre = new Taxonomy('genre');

$genre->register('book', true); // set 2nd parameter to true to make the taxonomy hierarchical

###adding more options setArgs($options) and setLabels($options) work the same as the custom post type options setters.

You can find more information about registering taxonomies here.

Also check the other examples on the examples folder.

##to-do

  • Make it Autoload ready.
  • Change to a different inflector and support pluralization for other languages. ICanBoogie/Inflector
  • Add testing.

##done

  • Add support for internationalization.

##contributing

Working on your first Pull Request? You can learn how from this free series How to Contribute to an Open Source Project on GitHub

Feel free to submit issues, pull requests, or suggestions.

You can also so reach me on twitter (@gillchristian) if you like it and/or are using it 😄

About

Helper class to create Custom Pots Types in WordPress.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages