我使用自定义帖子类型创建了一个wordpress照片库。
$gallery_labels = array(
'name' => _x('Gallery', 'post type general name', 'test' ),
'singular_name' => _x('Gallery', 'post type singular name', 'test' ),
'add_new' => _x('Add New', 'gallery', 'test' ),
'add_new_item' => __("Add New Gallery", 'test' ),
'edit_item' => __("Edit Gallery", 'test' ),
'new_item' => __("New Gallery", 'test' ),
'view_item' => __("View Gallery"),
'search_items' => __("Search Gallery", 'test' ),
'not_found' => __('No galleries found', 'test' ),
'not_found_in_trash' => __('No galleries found in Trash', 'test' ),
'parent_item_colon' => ''
);
$gallery_args = array(
'labels' => $gallery_labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'hierarchical' => true,
'menu_position' => null,
'has_archive' => true,
'can_export' => true,
'show_in_admin_bar' => true,
'exclude_from_search' => true,
'capability_type' => 'post',
'taxonomies' => array( 'post_tag', 'category'),
'supports' => array('title','editor','custom-fields','thumbnail','comments','excerpt','page-attributes'),
'menu_icon' => get_bloginfo('template_directory') . '/images/photo-album.png' //16x16 png if you want an icon
);
register_post_type('gallery', $gallery_args);
//----------------------------------------------
//------------------------create custom taxonomy
//----------------------------------------------
add_action( 'init', 'jss_create_gallery_taxonomies', 0);
function jss_create_gallery_taxonomies(){
register_taxonomy(
'phototype', 'gallery',
array(
'hierarchical'=> true,
'label' => 'Photo Categories',
'singular_label' => 'Category',
'query_var' => true,
'rewrite' => true
)
);
}
//----------------------------------------------
//--------------------------admin custom columns
//----------------------------------------------
//admin_init
add_action('manage_posts_custom_column', 'jss_custom_columns');
add_filter('manage_edit-gallery_columns', 'jss_add_new_gallery_columns');
function jss_add_new_gallery_columns( $columns ){
$columns = array(
'cb' => '<input type="checkbox">',
'jss_post_thumb' => 'Thumbnail',
'title' => 'Album Title',
'phototype' => 'Category',
'author' => 'Author',
'date' => 'Date'
);
return $columns;
}
function jss_custom_columns( $column ){
global $post;
switch ($column) {
case 'jss_post_thumb' : echo the_post_thumbnail('admin-list-thumb'); break;
case 'description' : the_excerpt(); break;
case 'phototype' : echo get_the_term_list( $post->ID, 'gallery', '', ', ',''); break;
}
}
//add thumbnail images to column
add_filter('manage_posts_columns', 'jss_add_post_thumbnail_column', 5);
add_filter('manage_pages_columns', 'jss_add_post_thumbnail_column', 5);
add_filter('manage_custom_post_columns', 'jss_add_post_thumbnail_column', 5);
// Add the column
function jss_add_post_thumbnail_column($cols){
$cols['jss_post_thumb'] = __('Thumbnail');
return $cols;
}
function jss_display_post_thumbnail_column($col, $id){
switch($col){
case 'jss_post_thumb':
if( function_exists('the_post_thumbnail') )
echo the_post_thumbnail( 'admin-list-thumb' );
else
echo 'Not supported in this theme';
break;
}
}
add_action( 'wp_ajax_nopriv_myajax-submit', 'myajax_submit' );
add_action( 'wp_ajax_myajax-submit', 'myajax_submit' );
function myajax_submit() {
// get the submitted parameters
$postID = $_POST['postID'];
$response = get_thumbnail_images();
$response = json_encode($response);
// response output
header( "Content-Type: application/json" );
echo $response;
// IMPORTANT: don't forget to "exit"
exit;
}
//----------------------------------------------
//--------------add theme support for thumbnails
//----------------------------------------------
add_filter( 'getarchives_where', 'custom_getarchives_where' );
function custom_getarchives_where( $where ){
$where = str_replace( "post_type = 'post'", "post_type IN ( 'post', 'gallery' )", $where );
return $where;
}
add_action( 'pre_get_posts', 'add_podcasts_to_archive' );
function add_podcasts_to_archive( $query ) {
if ( $query->is_main_query() && $query->is_archive() && !is_admin() )
$query->set( 'post_type', array( 'post', 'gallery' ) );
return $query;
}
function wp_list_categories_for_post_type($post_type, $args = '') {
$exclude = array();
// Check ALL categories for posts of given post type
foreach (get_categories() as $category) {
$posts = get_posts(array('post_type' => $post_type, 'category' => $category->cat_ID));
// If no posts found, ...
if (empty($posts))
// ...add category to exclude list
$exclude[] = $category->cat_ID;
}
// Set up args
if (! empty($exclude)) {
$args .= ('' === $args) ? '' : '&';
$args .= 'exclude='.implode(',', $exclude);
}
// List categories
wp_list_categories($args);
}
在前端工作得很好但在管理员中我没看到缩略图和类别
以下是我正在谈论的屏幕截图http://s12.postimg.org/mqtkb274t/gallery.png
我不明白哪里可能是问题我还添加了管理员80 x 80的缩略图支持,但不是这个代码