Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://wp.tutsplus.com/tutorials/creative-coding/custom-post-type-helper-class/
- // call to the class ##
- $cpt_tree = new Custom_Post_Type( "tree" ); // singular custom post type title ##
- ....
- $cpt_tree_admin_column_args = array ( // tree admin colums args ##
- 'tag' => true,
- 'category' => true,
- );
- $cpt_tree->add_admin_columns( $cpt_tree_admin_column_args ); // add admin columns ##
- class Custom_Post_Type {
- .....
- // this code is added inside the main Custom Post Type class
- public function add_admin_columns( $args )
- {
- // We need to know the Post Type name again ##
- $name = strtolower( $this->post_type_name );
- // Columns args ##
- $column_args = $args;
- // Default arguments, overwitten with the given arguments
- $args = array_merge(
- // Default
- array(
- 'tag' => true,
- 'category' => false,
- ),
- // Given
- $column_args
- );
- add_filter( 'manage_edit-'.$name.'_columns',
- function() use( $name, $args )
- {
- $new_columns['cb'] = '<input type="checkbox" />';
- $new_columns['title'] = _x(''.ucwords($name).'', 'column name');
- $new_columns['author'] = __('Author');
- if ( $args["category"] === true ) { // add category column ##
- $new_columns[''.$name.'_category'] = __('Categories');
- }
- if ( $args["tag"] === true ) { // add tag column ##
- $new_columns[''.$name.'_tag'] = __('Tags');
- }
- $new_columns['thumbnail'] = __('Thumbnail');
- $new_columns['date'] = _x('Date', 'column name');
- return $new_columns;
- }
- , 10, 2 );
- if ( !function_exists('manage_cpt_columns') ) {
- add_action('manage_'.$name.'_posts_custom_column', 'manage_cpt_columns', 10, 2);
- function manage_cpt_columns( $column_name, $id ) {
- global $wpdb, $name, $post;
- #echo ' - C: '.$column_name;
- $name = get_post_type( $post );
- #echo 'N: '.$name;
- switch ( $column_name ) {
- case $name.'_tag':
- $tags = get_the_terms( $id, ''.$name.'_tag' ); // cpt_tag is the custom taxonomy slug
- if ( !empty( $tags ) ) {
- $out = array();
- foreach ( $tags as $c )
- $out[] = "<a href='edit-tags.php?action=edit&taxonomy=".$name."_tag&tag_ID=$c->term_id&post_type=".$name."'> " . esc_html(sanitize_term_field('name', $c->name, $c->term_id, ''.$name.'_tag', 'display')) . "</a>";
- echo join( ', ', $out );
- } else {
- echo ''; //No Taxonomy term defined
- }
- break;
- case $name.'_category':
- $tags = get_the_terms( $id, ''.$name.'_category' ); // cpt_category is the custom taxonomy slug
- if ( !empty( $tags ) ) {
- $out = array();
- foreach ( $tags as $c )
- $out[] = "<a href='edit-tags.php?action=edit&taxonomy=".$name."_category&tag_ID=$c->term_id&post_type=".$name."'> " . esc_html(sanitize_term_field('name', $c->name, $c->term_id, ''.$name.'_category', 'display')) . "</a>";
- echo join( ', ', $out );
- } else {
- echo ''; //No Taxonomy term defined
- }
- break;
- case 'thumbnail':
- if( function_exists('the_post_thumbnail') ) {
- #echo the_post_thumbnail( 'admin-list-thumb' );
- } else {
- echo '';
- }
- break;
- break;
- default:
- break;
- } // end switch
- }}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement