hlashbrooke / WordPress-Plugin-Template

A robust code template for creating a standards-compliant WordPress plugin.
https://hughlashbrooke.com/
GNU General Public License v2.0
1.03k stars 329 forks source link

added options to allow control of Post Type and Taxonomy Options #32

Closed mohamedhamad closed 9 years ago

mohamedhamad commented 9 years ago

An options array can now be passed to define extra details of a post type and a taxonomy.

eg: Post Type, you can now pass an array to define menu_icon, rewrite, archive settings, search exclusion.

WordPress_Plugin_Template()->register_post_type(
                        'post_type',
                        __( 'Plural Name',     'wordpress-plugin-template' ),
                        __( 'Singular Name',      'wordpress-plugin-template' ),
                        __( 'Description', 'wordpress-plugin-template'),
                        array(
                          'menu_icon'=>plugins_url( 'assets/img/cpt-icon.png', __FILE__ ),
                          'rewrite' => array('slug' =>'post_type_slug'),
                          'exclude_from_search' => false,
                          'has_archive'     => true,
                          'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'page-attributes' ),
                        )
                    );

eg: Taxonomy hierarchical options to differentiate between a category or tag type taxonomy, rewrite options with slug and hierarchical display

WordPress_Plugin_Template()->register_taxonomy(
    'taxonomy_name',
    __( 'Plural Name', 'wordpress-plugin-template' ),
    __( 'Singular Name', 'wordpress-plugin-template' ),
    'post_type',
    array(
      'hierarchical'=>false,
      'rewrite'=>array('slug'=>'taxonomy_slug', 'hierarchical' => true),
    )
  );
hlashbrooke commented 9 years ago

This is very cool - thanks for the working on this and contributing it back! :)

mohamedhamad commented 9 years ago

glad to help. use this all the time. would love to contribute more.