Created
May 7, 2011 23:36
-
-
Save clawfire/960965 to your computer and use it in GitHub Desktop.
Wordpress custom post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*-----------------------------------------------------------------------------------*/ | |
/* Create a new post type called course | |
/*-----------------------------------------------------------------------------------*/ | |
function create_post_type_courses() | |
{ | |
$labels = array( | |
'name' => __( 'Course'), | |
'singular_name' => __( 'Course' ), | |
'rewrite' => array('slug' => __( 'courses' )), | |
'add_new' => _x('Add New', 'slide'), | |
'add_new_item' => __('Add New Course'), | |
'edit_item' => __('Edit Course'), | |
'new_item' => __('New Course'), | |
'view_item' => __('View Course'), | |
'search_items' => __('Search Course'), | |
'not_found' => __('No courses found'), | |
'not_found_in_trash' => __('No courses found in Trash'), | |
'parent_item_colon' => '' | |
); | |
$args = array( | |
'labels' => $labels, | |
'public' => true, | |
'publicly_queryable' => true, | |
'show_ui' => true, | |
'query_var' => true, | |
'rewrite' => true, | |
'capability_type' => 'post', | |
'hierarchical' => false, | |
'menu_position' => null, | |
'supports' => array('title','editor','thumbnail','custom-fields','excerpt') | |
); | |
register_post_type(__( 'course' ),$args); | |
} | |
/*-----------------------------------------------------------------------------------*/ | |
/* All the pre-made messages for the course post type | |
/*-----------------------------------------------------------------------------------*/ | |
function course_updated_messages( $messages ) { | |
$messages[__( 'course' )] = | |
array( | |
0 => '', // Unused. Messages start at index 1. | |
1 => sprintf( __('Course updated. <a href="%s">View course</a>'), esc_url( get_permalink($post_ID) ) ), | |
2 => __('Custom field updated.'), | |
3 => __('Custom field deleted.'), | |
4 => __('Course updated.'), | |
/* translators: %s: date and time of the revision */ | |
5 => isset($_GET['revision']) ? sprintf( __('Course restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, | |
6 => sprintf( __('Course published. <a href="%s">View course</a>'), esc_url( get_permalink($post_ID) ) ), | |
7 => __('Course saved.'), | |
8 => sprintf( __('Course submitted. <a target="_blank" href="%s">Preview course</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), | |
9 => sprintf( __('Course scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview course</a>'), | |
// translators: Publish box date format, see http://php.net/date | |
date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ), | |
10 => sprintf( __('Course draft updated. <a target="_blank" href="%s">Preview course</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), | |
); | |
return $messages; | |
} | |
/*-----------------------------------------------------------------------------------*/ | |
/* Create custom taxonomies for the portfolio post type | |
/*-----------------------------------------------------------------------------------*/ | |
function build_taxonomies(){ | |
register_taxonomy(__( "semester" ), array(__( "course" )), array("hierarchical" => false, "label" => __( "Semesters" ), "singular_label" => __( "Semester" ), "rewrite" => array('slug' => 'semester', 'hierarchical' => false))); | |
register_taxonomy(__( "faculty-member" ), array(__( "course" )), array("hierarchical" => false, "label" => __( "Faculty members" ), "singular_label" => __( "Faculty member" ), "rewrite" => array('slug' => 'faculty', 'hierarchical' => false))); | |
register_taxonomy(__( "type" ), array(__( "course" )), array("hierarchical" => false, "label" => __( "Types" ), "singular_label" => __( "Type" ), "rewrite" => array('slug' => 'type', 'hierarchical' => false))); | |
} | |
/*-----------------------------------------------------------------------------------*/ | |
/* Edit the courses columns | |
/*-----------------------------------------------------------------------------------*/ | |
function course_edit_columns($columns){ | |
$columns = array( | |
"cb" => "<input type=\"checkbox\" />", | |
"title" => __( 'Course Title' ), | |
"semester" => __( 'semester' ), | |
"faculty-member" => __( 'faculty' ), | |
"type" => __( 'type' ) | |
); | |
return $columns; | |
} | |
/*-----------------------------------------------------------------------------------*/ | |
/* Show the taxonomies within the columns | |
/*-----------------------------------------------------------------------------------*/ | |
function courses_custom_columns($column){ | |
global $post; | |
switch ($column) | |
{ | |
case __( 'type' ): | |
echo get_the_term_list($post->ID, __( 'type' ), '', ', ',''); | |
break; | |
case __( 'semester' ): | |
echo get_the_term_list($post->ID, __( 'semester' ), '', ', ',''); | |
break; | |
case __( 'faculty-member' ): | |
echo get_the_term_list($post->ID, __( 'faculty-member' ), '', ', ',''); | |
break; | |
} | |
} | |
/*-----------------------------------------------------------------------------------*/ | |
/* Rock'n'Roll | |
/*-----------------------------------------------------------------------------------*/ | |
add_action( 'init', 'create_post_type_courses' ); | |
add_action( 'init', 'build_taxonomies', 0 ); | |
add_filter('post_updated_messages', 'course_updated_messages'); | |
add_filter("manage_edit-course_columns", "course_edit_columns"); | |
add_action("manage_posts_custom_column", "courses_custom_columns"); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment