PHP 自定义职位类型:董事会
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 自定义职位类型:董事会相关的知识,希望对你有一定的参考价值。
/******* CUSTOM POST TYPE: BOARD OF DIRECTORS *********/
add_action('init', 'bod_register');
function bod_register() {
$args = array(
'label' => __('Board of Directors'),
'singular_label' => __('Board Member'),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => true,
'supports' => array('title', 'thumbnail')
);
register_post_type( 'board-member' , $args );
}
add_action("admin_init", "bod_admin_init");
add_action('save_post', 'save_bod_meta');
function bod_admin_init(){
add_meta_box("bod_meta", "Board Member Options", "bod_meta_options", "board-member", "normal", "core");
}
function bod_meta_options(){
global $post;
$custom = get_post_custom($post->ID);
$bod_suffix = $custom["bod_suffix"][0];
$bod_position = $custom["bod_position"][0];
?>
<div style="float:left;padding:5px 15px;">
<label for="bod_suffix">Suffix </label>
<input type="text" name="bod_suffix" size="20" autocomplete="on" value="<?php echo $bod_suffix; ?>">
</div>
<div style="float:left;padding:5px 15px;">
<label for="bod_position">Position </label>
<input type="text" name="bod_position" size="30" autocomplete="on" value="<?php echo $bod_position; ?>">
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<?php
}
function save_bod_meta(){
global $post;
update_post_meta($post->ID, "bod_suffix", $_POST["bod_suffix"]);
update_post_meta($post->ID, "bod_position", $_POST["bod_position"]);
}
add_filter("manage_edit-board-member_columns", "bod_edit_columns");
add_action("manage_posts_custom_column", "bod_custom_columns");
function bod_edit_columns($columns){
$columns = array(
"cb" => "<input type=\"checkbox\" />",
"title" => "Name",
"bod_suffix" => "Suffix",
"bod_position" => "Position",
"bod_image" => "Featured Image"
);
return $columns;
}
function bod_custom_columns($column){
global $post;
switch ($column)
{
case "bod_suffix":
$custom = get_post_custom();
echo $custom["bod_suffix"][0];
break;
case "bod_position":
$custom = get_post_custom();
echo $custom["bod_position"][0];
break;
case "bod_image":
$sl_thumb = get_thumbnail($post->ID,"60","75");
echo "<img src=\"". $sl_thumb ."\" />";
break;
}
}
以上是关于PHP 自定义职位类型:董事会的主要内容,如果未能解决你的问题,请参考以下文章
赵伟国辞去TCL集团董事等职位,紫光参与TCL定增浮盈已超7亿