theme - 2

增加新的post type

 1 // Add new post type for Recipes
 2 add_action('init', 'cooking_recipes_init');
 3 function cooking_recipes_init() 
 4 {
 5     $recipe_labels = array(
 6         'name' => _x('Recipes', 'post type general name'),
 7         'singular_name' => _x('Recipe', 'post type singular name'),
 8         'all_items' => __('All Recipes'),
 9         'add_new' => _x('Add new recipe', 'recipes'),
10         'add_new_item' => __('Add new recipe'),
11         'edit_item' => __('Edit recipe'),
12         'new_item' => __('New recipe'),
13         'view_item' => __('View recipe'),
14         'search_items' => __('Search in recipes'),
15         'not_found' =>  __('No recipes found'),
16         'not_found_in_trash' => __('No recipes found in trash'), 
17         'parent_item_colon' => ''
18     );
19     $args = array(
20         'labels' => $recipe_labels,
21         'public' => true,
22         'publicly_queryable' => true,
23         'show_ui' => true, 
24         'query_var' => true,
25         'rewrite' => true,
26         'capability_type' => 'post',
27         'hierarchical' => false,
28         'menu_position' => 5,
29         'supports' => array('title','editor','author','thumbnail','excerpt','comments','custom-fields'),
30         'has_archive' => 'recipes'
31     ); 
32     register_post_type('recipes',$args);
33 }

 

在后台管理界面,给新的post type菜单项增加icon

 1 // Add new Custom Post Type icons
 2 add_action( 'admin_head', 'cooking_icons' );
 3 function cooking_icons() {
 4     ?>
 5     <style type="text/css" media="screen">
 6         #menu-posts-recipes .wp-menu-image {
 7             background: url(<?php bloginfo('url') ?>/wp-content/themes/images/recipessmall.png) no-repeat 6px !important;
 8         }
 9         .icon32-posts-recipes {
10             background: url(<?php bloginfo('url') ?>/wp-content/themes/images/recipes.png) no-repeat !important;
11         }
12         #menu-posts-photos .wp-menu-image {
13             background: url(<?php bloginfo('url') ?>/wp-content/themes/images/photosmall.png) no-repeat 6px !important;
14         }
15         .icon32-posts-photos {
16             background: url(<?php bloginfo('url') ?>/wp-content/themes/images/photo.png) no-repeat !important;
17         }
18         #menu-posts-videos .wp-menu-image {
19             background: url(<?php bloginfo('url') ?>/wp-content/themes/images/videosmall.png) no-repeat 6px !important;
20         }
21         .icon32-posts-videos {
22             background: url(<?php bloginfo('url') ?>/wp-content/themes/images/video.png) no-repeat !important;
23         }
24 
25     </style>
26 <?php } 

 

增加新的taxonomy:

 1 // Add custom taxonomies
 2 add_action( 'init', 'cooking_create_taxonomies', 0 );
 3 
 4 function cooking_create_taxonomies() 
 5 {
 6     // Meal type
 7     $meal_labels = array(
 8         'name' => _x( 'Meal type', 'taxonomy general name' ),
 9         'singular_name' => _x( 'Meal type', 'taxonomy singular name' ),
10         'search_items' =>  __( 'Search in meal type' ),
11         'all_items' => __( 'All meal type' ),
12         'most_used_items' => null,
13         'parent_item' => null,
14         'parent_item_colon' => null,
15         'edit_item' => __( 'Edit meal type' ), 
16         'update_item' => __( 'Update meal type' ),
17         'add_new_item' => __( 'Add new meal type' ),
18         'new_item_name' => __( 'New meal type' ),
19         'menu_name' => __( 'Meal type' ),
20     );
21     register_taxonomy('meal-type',array('recipes','photos','videos'),array(
22         'hierarchical' => true,
23         'labels' => $meal_labels,
24         'show_ui' => true,
25         'query_var' => true,
26         'rewrite' => array('slug' => 'meal-type' )
27     ));}

posted on 2012-08-29 10:17  kalintw  阅读(165)  评论(0)    收藏  举报

导航