Monday, May 21, 2012

wordpress Custom Post Types

By default, WordPress offers two different types of posts for content. First, you 
have the traditional “post”, used most often for what WordPress is known best for
 – blogging. Second, you have “pages”. Each of these, as far as WordPress is 
concerned, is a type of “post”. A custom post type is a type of post that you 
define. 

add_action('init', 'register_news, 1); // Set priority to avoid plugin conflicts
 
    function register_news() { // A unique name for our function
        $labels = array( // Used in the WordPress admin
                'name' => _x('News & Event', 'post type general name'),
                'singular_name' => _x('event', 'post type singular name'),
                'add_new' => _x('Add New', 'Event'),
                'add_new_item' => __('Add New Event'),
                'edit_item' => __('Edit Event'),
                'new_item' => __('New Event'),
                'view_item' => __('View Event '),
                'search_items' => __('Search Event'),
                'not_found' =>  __('Nothing found'),
                'not_found_in_trash' => __('Nothing found in Trash')
        );
        $file_dir=get_bloginfo('template_directory');
        $args = array(
                'labels' => $labels, // Set above
                'public' => true, // Make it publicly accessible
                'hierarchical' => false, // No parents and children here
                'menu_position' => 5, // Appear right below "Posts"
                'has_archive' => 'event', // Activate the archive
                'menu_icon' => $file_dir.'/images/faq.png',
                'supports' => array('title','author','editor','comments','thumbnail','custom-fields'),
        );
        
        register_taxonomy("catalog", array("event"), array("hierarchical" => true, "label" => "Categories", "singular_label" => "event", "rewrite" => true));
        register_post_type( 'event', $args ); // Create the post type, use options above
 }
?> 

No comments:

Post a Comment