Custom Post Type Funktion

Um automatisch und schnell neue Post Types in WordPress zu kreieren habe ich diese Funktion in meiner functions.php.
Sie macht eigentlich nichts anderes als das “Ausfüllen” der Registrierungen dieser neuen Beitragsarten. Aufgerufen wird sie mit dem Singular und dem Plural des zu erstellenden Beitragstyps, z.B. post_type_init( 'Projekt', 'Projekte' );
Dies kann natürlich auch über ein Array gelöst werden, welches von einem Anderen Programmteil gespeist wird, wie etwa einer Theme Option, die im WordPress ganz Usernah gepflegt werden kann.

Nachteil an dieser Funktion ist natürlich dass die Beitragstypen immer in der gleichen Form erstellt werden und lediglich verschiedene Namen erhalten, um allerdings eine Gliederung in die Seite zu bekommen oder weitergehend beim Darstellen der Post Types damit zu arbeiten (was wohl der häufigste Fall hierfür sein dürfte) ist die Lösung nicht schlecht.

add_action( 'init_post_types', 'post_type_init', 10, 2 );

/**
* Register a post type.
*
* @link http://codex.wordpress.org/Function_Reference/register_post_type
*/
function post_type_init( $singular, $plural, $wp_customize ) {

$labels = array(
'name'               => _x( $singular, 'post type general name', 'yourWPTextDomain' ),
'singular_name'      => _x( $singular, 'post type singular name', 'yourWPTextDomain' ),
'menu_name'          => _x( $singular, 'admin menu', 'yourWPTextDomain' ),
'name_admin_bar'     => _x( $singular, 'add new on admin bar', 'yourWPTextDomain' ),
'add_new'            => _x( 'Add New', strtolower( $plural ), 'yourWPTextDomain' ),
'add_new_item'       => __( 'Add New ' . $singular, 'yourWPTextDomain' ),
'new_item'           => __( 'New ' . $singular, 'yourWPTextDomain' ),
'edit_item'          => __( 'Edit ' . $singular, 'yourWPTextDomain' ),
'view_item'          => __( 'View ' . $singular, 'yourWPTextDomain' ),
'all_items'          => __( 'Alle ' . $plural, 'yourWPTextDomain' ),
'search_items'       => __( 'Suche ' . $plural, 'yourWPTextDomain' ),
'parent_item_colon'  => __( 'Eltern-' . $plural, 'yourWPTextDomain' ),
'not_found'          => __( 'Keine ' . $plural . ' gefunden.', 'yourWPTextDomain' ),
'not_found_in_trash' => __( 'Keine ' . $plural . ' gefunden im Papierkorb.', 'yourWPTextDomain' )
);

$args = array(
'labels'             => $labels,
'description'        => __( 'Description.', 'yourWPTextDomain' ),
'public'             => true,
'publicly_queryable' => true,
'show_ui'            => true,
'show_in_menu'       => true,
'show_in_nav_menus'  => true,
'query_var'          => true,
'rewrite'            => array( 'slug' => strtolower( $plural ) ),
'capability_type'    => 'post',
'has_archive'        => true,
'hierarchical'       => true,
'taxonomies'         => array( strtolower( $singular ) . 'category' ),
'menu_position'      => 5,
//    5 - below Posts
//    10 - below Media
//    15 - below Links
//    20 - below Pages
//    25 - below comments
//    60 - below first separator
//    65 - below Plugins
//    70 - below Users
//    75 - below Tools
//    80 - below Settings
//    100 - below second separator

'supports' => array(
'editor',
'author',
'thumbnail',
'excerpt',
'trackbacks',
'custom-fields',
'comments',
'revisions',
'title',
'categories'
)
);

register_taxonomy(
strtolower( $singular ) . 'category',
$singular,
$tax_args = array(
'label'             => __( $singular . 'kategorie', 'yourWPTextDomain' ),
'public'            => true,
'hierarchical'      => true,
'show_ui'           => true,
'show_admin_column' => true,
'show_in_nav_menus' => true
)
);
register_post_type( strtolower( $plural ), $args );

}