Skip to content

Instantly share code, notes, and snippets.

@hilukasz
Created June 9, 2012 19:14
Show Gist options
  • Save hilukasz/2902223 to your computer and use it in GitHub Desktop.
Save hilukasz/2902223 to your computer and use it in GitHub Desktop.
<?php
//########################################################
// edit custom columns display for back-end
//########################################################
// ADDING CUSTOM POST TYPE
add_filter( 'manage_posts_columns', 'fb_AddThumbColumn' );
add_action( 'manage_posts_custom_column', 'fb_AddThumbValue', 10, 2 );
// for investments
add_filter( 'manage_team_columns', 'fb_AddThumbColumn' );
add_action( 'manage_team_custom_column', 'fb_AddThumbValue', 10, 2 ); //employees
add_action( 'manage_portfolio_custom_column', 'fb_AddThumbValue', 10, 2 ); //portfolio
// for posts
add_action("manage_posts_custom_column", "my_custom_columns");
add_filter("manage_edit-team_columns", "my_team_columns"); //employees
add_filter("manage_edit-portfolio_columns", "my_portfolio_columns"); //portfolio
// employees
function my_team_columns($columns) //this function display the columns headings
{
$columns = array(
"cb" => "<input type=\"checkbox\" />",
"title" => "Employee Name",
"description" => "Description",
"thumbnail" => "Picture"
);
return $columns;
}
//portfolio
function my_portfolio_columns($columns) //this function display the columns headings
{
$columns = array(
"cb" => "<input type=\"checkbox\" />",
"title" => "Project name",
"description" => "Description",
"thumbnail" => "Picture"
);
return $columns;
}
// both
function my_custom_columns($column)
{
global $post;
if ("ID" == $column) echo $post->ID; //displays title
elseif ("description" == $column) echo $post->post_content; //displays the content excerpt
elseif ("thumbnail" == $column) echo $post->post_thumbnail; //shows up our post thumbnail that we previously created.
}
//########################################################
// multiple custom post types
//########################################################
add_action('init', 'all_custom_post_types');
function all_custom_post_types() {
$types = array(
// employees
array('the_type' => 'team',
'single' => 'employee',
'plural' => 'employees'),
// portfolio
array('the_type' => 'portfolio',
'single' => 'portfolio',
'plural' => 'portfolio'),
//news
array('the_type' => 'news',
'single' => 'news',
'plural' => 'news'),
);
foreach ($types as $type) {
$the_type = $type['the_type'];
$single = $type['single'];
$plural = $type['plural'];
$labels = array(
'name' => _x($plural, 'post type general name'),
'singular_name' => _x($single, 'post type singular name'),
'add_new' => _x('Add New', $single),
'add_new_item' => __('Add New '. $single),
'edit_item' => __('Edit '.$single),
'new_item' => __('New '.$single),
'view_item' => __('View '.$single),
'search_items' => __('Search '.$plural),
'not_found' => __('No '.$plural.' found'),
'not_found_in_trash' => __('No '.$plural.' 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' => 5,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpts', 'revisions') //the editing regions that will support
);
register_post_type($the_type, $args);
}
}
// employees
register_taxonomy("position", array("team"), array("hierarchical" => true, "label" => "Edit Positions", "singular_label" => "position", "rewrite" => true));
//portfolio
register_taxonomy( 'division', 'portfolio', array( 'hierarchical' => true, 'label' => 'Division', 'query_var' => true, 'rewrite' => true ) );
register_taxonomy( 'specifics', 'portfolio', array( 'hierarchical' => true, 'label' => 'Specifics', 'query_var' => true, 'rewrite' => true ) );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment