goldenapple最初的回答给了我完成这项工作所需的快速启动。
功能。php下面是我用来添加新帖子类型“header image”并相应修改其他管理屏幕的完整代码:
/**
* Register the Header Image custom post type.
*/
function sixohthree_init() {
$labels = array(
\'name\' => \'Header Images\',
\'singular_name\' => \'Header Image\',
\'add_new_item\' => \'Add Header Image\',
\'edit_item\' => \'Edit Header Image\',
\'new_item\' => \'New Header Image\',
\'view_item\' => \'View Header Image\',
\'search_items\' => \'Search Header Images\',
\'not_found\' => \'No Header Images found\',
\'not_found_in_trash\' => \'No Header Images found in Trash\'
);
$args = array(
\'labels\' => $labels,
\'public\' => false,
\'show_ui\' => true,
\'supports\' => array(\'thumbnail\')
);
register_post_type( \'header-image\', $args );
}
add_action( \'init\', \'sixohthree_init\' );
/**
* Modify which columns display when the admin views a list of header-image posts.
*/
function sixohthree_headerimage_posts_columns( $posts_columns ) {
$tmp = array();
foreach( $posts_columns as $key => $value ) {
if( $key == \'title\' ) {
$tmp[\'header-image\'] = \'Header Image\';
} else {
$tmp[$key] = $value;
}
}
return $tmp;
}
add_filter( \'manage_header-image_posts_columns\', \'sixohthree_headerimage_posts_columns\' );
/**
* Custom column output when admin is view the header-image post list.
*/
function sixohthree_headerimage_custom_column( $column_name ) {
global $post;
if( $column_name == \'header-image\' ) {
echo "<a href=\'", get_edit_post_link( $post->ID ), "\'>", get_the_post_thumbnail( $post->ID ), "</a>";
}
}
add_action( \'manage_posts_custom_column\', \'sixohthree_headerimage_custom_column\' );
/**
* Make the "Featured Image" metabox front and center when editing a header-image post.
*/
function sixohthree_headerimage_metaboxes( $post ) {
global $wp_meta_boxes;
remove_meta_box(\'postimagediv\', \'header-image\', \'side\');
add_meta_box(\'postimagediv\', __(\'Featured Image\'), \'post_thumbnail_meta_box\', \'header-image\', \'normal\', \'high\');
}
add_action( \'add_meta_boxes_header-image\', \'sixohthree_headerimage_metaboxes\' );
/**
* Enable thumbnail support in the theme, and set the thumbnail size.
*/
function sixohthree_after_setup() {
add_theme_support( \'post-thumbnails\' );
set_post_thumbnail_size(150, 100, true);
}
add_action( \'after_setup_theme\', \'sixohthree_after_setup\' );
管理屏幕截图
模板代码
$header_images = get_posts(\'post_type=header-image&orderby=rand&numberposts=2\');
foreach( $header_images as $idx => $post ) {
setup_postdata($post);
the_post_thumbnail(\'post-thumbnail\', array(\'class\' => \'snapshot snapshot\' . ($idx+1) ) );
}