Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Custom Post Type Test
- Plugin URI: http://zed1.com/
- Description: Testing Custom Post Types in WordPress 3.1
- Author: Mike Little
- Version: 0.1.0
- Author URI: http://zed1.com/
- License: GPLv2 or later
- */
- new cpt(); // kick it all off
- register_activation_hook( __FILE__, array( 'cpt', 'activation' ) );
- register_deactivation_hook( __FILE__, array( 'cpt', 'deactivation' ) );
- class cpt {
- function __construct() {
- add_action( 'init', array( 'cpt', 'init' ) );
- } // end constructor
- static function activation() {
- self::register_cpt();
- self::flush_rules();
- } // end activation
- static function deactivation() {
- self::flush_rules();
- } // end deactivation
- static function flush_rules() {
- flush_rewrite_rules();
- } // end deactivation
- static function init() {
- self::register_cpt();
- } // end init
- static function register_cpt() {
- if ( !post_type_exists( 'cpt' ) ) {
- $labels = array( 'name' => _x( 'CPTs', 'post type general name' ),
- 'singular_name' => _x( 'CPT', 'post type singular name' ),
- 'add_new' => _x( 'New CPT', 'add new singular name' ),
- 'add_new_item' => __( 'Add New CPT' ),
- 'edit_item' => __( 'Edit CPT' ),
- 'new_item' => __( 'New CPT' ),
- 'view_item' => __( 'View CPT' ),
- 'search_items' => __( 'Search CPTs' ),
- 'not_found' => __( 'No CPTs Found' ),
- 'not_found_in_trash' => __( 'No CPTs found in Trash' ),
- 'parent_item_colon' => '-:-'
- );
- $args = array( 'labels' => $labels,
- 'public' => true,
- 'publicly_queryable' => true,
- 'show_ui' => true,
- 'query_var' => true,
- 'rewrite' => array( 'slug' => 'cpt',
- 'with_front' => true,
- 'feeds' => false,
- 'feed' => false,
- 'pages' => true,
- 'ep_mask' => 0 //(EP_ROOT)
- ),
- 'has_archive' => 'cpts',
- 'capability_type' => 'post',
- 'hierarchical' => true,
- 'show_in_nav_menus' => true,
- 'menu_position' => 100, // last block
- 'supports' => array( 'title',
- 'editor',
- 'excerpt',
- //'comments',
- 'revisions',
- 'page-attributes',
- 'shortlink' )
- );
- register_post_type( 'cpt', $args );
- }
- } // end register_cpt
- } // end class cpt
- /* put this in your side bar
- <?php list_cpts(); ?>
- */
- function list_cpts( $args = array() ) {
- global $post;
- $default_args = array( 'post_type'=>'cpt', 'title_li'=> __('CPTs') );
- if ( is_single() && ( 'cpt' == $post->post_type ) ) {
- if ( $parent_id = wp_get_post_parent_id( $post->ID ) ) {
- $default_args['child_of'] = $parent_id; // get siblings
- } else {
- $default_args['child_of'] = $post->ID; // get children
- }
- }
- $args = array_merge( $default_args, $args );
- return wp_list_pages( $args );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement