Advertisement
Guest User

Custom投稿

a guest
Nov 20th, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.18 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. // =====================
  5. // ! CUSTOM POST TYPES
  6. // =====================
  7.  
  8. add_action( 'init', 'flamingo_custom_types_register',1 );
  9. function flamingo_custom_types_register() {
  10.  
  11.     $flamingo_option = vankarwai_get_global_options();
  12.     if(isset($flamingo_option['flamingo_portfolio_slug'])){ $portfolio_slug = $flamingo_option['flamingo_portfolio_slug']; } else { $portfolio_slug='portfolio'; }
  13.  
  14.     /*
  15.         PROJECT TYPE: Custom Taxonomy for 'Portfolio'
  16.         Note: Register the taxonomy before custom post type due to wp_rewrite behaviour
  17.     */
  18.     $project_cat_labels = array(
  19.         'name'                          => _x('Project Type','taxonomy general name','flamingo'),
  20.         'singular_name'                 => _x('Project Type','taxonomy singular name','flamingo'),
  21.         'search_items'                  => __('Search Project Types','flamingo'),
  22.         'popular_items'                 => __('Popular Project Types','flamingo' ),
  23.         'all_items'                     => __('All Project Types','flamingo'),
  24.         'parent_item'                   => __('Parent Project Types','flamingo'),
  25.         'edit_item'                     => __('Edit Project Type','flamingo'),
  26.         'update_item'                   => __('Update Project Type','flamingo'),
  27.         'add_new_item'                  => __('Add Project Type','flamingo'),
  28.         'new_item_name'                 => __('New Project Type','flamingo'),
  29.         'add_or_remove_items'           => __('Add or remove Project Types','flamingo')
  30.     );
  31.  
  32.     $args = array(
  33.         'label'                         => __('Project Type', 'flamingo'),
  34.         'labels'                        => $project_cat_labels,
  35.         'public'                        => true,
  36.         'hierarchical'                  => true,
  37.         'show_ui'                       => true,
  38.         'show_in_nav_menus'             => true,
  39.         'rewrite'                       => array( 'slug' => $portfolio_slug.'/type', 'with_front' => true ),
  40.         'query_var'                     => true
  41.     );
  42.     register_taxonomy( 'portfolio_type', 'portfolio', $args );
  43.  
  44.  
  45.     /*
  46.         PORTFOLIO: Custom Post Type
  47.     */
  48.  
  49.     $projects_labels = array(
  50.         'name'                  => _x('Portfolio','post type general name','flamingo'),
  51.         'singular_name'         => _x('Project','post type singular name','flamingo'),
  52.         'add_new'               => _x('Add New Project','portfolio','flamingo'),
  53.         'add_new_item'          => __('Add New Project','flamingo'),
  54.         'edit_item'             => __('Edit Project','flamingo'),
  55.         'new_item'              => __('New Project','flamingo'),
  56.         'view_item'             => __('View Project','flamingo'),
  57.         'search_items'          => __('Search Project','flamingo'),
  58.         'not_found'             => __('No Project found','flamingo'),
  59.         'not_found_in_trash'    => __('No Project found in Trash','flamingo')
  60.     );
  61.  
  62.     $projects_args = array(
  63.         'labels'                => $projects_labels,
  64.         'public'                => true,
  65.         'show_ui'               => true,
  66.         'query_var'             => true,
  67.         'show_in_menu'          => true,
  68.         'menu_position'         => 5,
  69.         'capability_type'       => 'post',
  70.         'supports'              => array( 'title', 'editor', 'thumbnail', 'page-attributes' ),
  71.         'rewrite'               => array( 'slug' => $portfolio_slug, 'with_front' => true ),
  72.         'has_archive'           => true
  73.     );
  74.  
  75.     register_post_type( 'portfolio' , $projects_args );
  76.  
  77. }
  78.  
  79. /* Add new columns for PORTFOLIO custom post type */
  80. function flamingo_portfolio_columns_head($defaults) {
  81.     $defaults['project_image'] = __("Project Image","flamingo");
  82.     $defaults['project_client'] = __("Client","flamingo");
  83.     return $defaults;
  84. }
  85. function flamingo_portfolio_columns_content($column_name, $post_ID) {
  86.     if ($column_name == 'project_image') {
  87.         $project_image = flamingo_get_featured_image($post_ID);
  88.         if ($project_image) {
  89.             echo '<img width="100" src="' . $project_image . '" />';
  90.         }
  91.     }
  92.  
  93.     if ($column_name == 'project_client') {
  94.         $project_client = get_post_meta($post_ID, 'project_client', true);
  95.         if ($project_client) {
  96.             echo $project_client;
  97.         }
  98.     }
  99. }
  100. add_filter('manage_edit-portfolio_columns', 'flamingo_portfolio_columns_head');
  101. add_action('manage_portfolio_posts_custom_column', 'flamingo_portfolio_columns_content', 10, 2);
  102.  
  103.  
  104. /* Add new columns for SLIDER IMAGE custom post type */
  105. function flamingo_slider_columns_head($defaults) {
  106.     $defaults['slider_image'] = __("Featured Image","flamingo");
  107.     return $defaults;
  108. }
  109. function flamingo_slider_columns_content($column_name, $post_ID) {
  110.     if ($column_name == 'slider_image') {
  111.         $slider_image = flamingo_get_featured_image($post_ID);
  112.         if ($slider_image) {
  113.             echo '<img width="100" src="' . $slider_image . '" />';
  114.         }
  115.     }
  116. }
  117. add_filter('manage_edit-slider_columns', 'flamingo_slider_columns_head');
  118. add_action('manage_slider_posts_custom_column', 'flamingo_slider_columns_content', 10, 2);
  119.  
  120.  
  121.  
  122. /* Get featured image */
  123. function flamingo_get_featured_image($post_ID) {
  124.     $post_thumbnail_id = get_post_thumbnail_id($post_ID);
  125.     if ($post_thumbnail_id) {
  126.         $post_thumbnail_img = wp_get_attachment_image_src($post_thumbnail_id, 'featured-thumbnail');
  127.         return $post_thumbnail_img[0];
  128.     }
  129. }
  130.  
  131. add_action('do_meta_boxes', 'flamingo_slider_image_metabox');
  132.  
  133. function flamingo_slider_image_metabox(){
  134.     remove_meta_box( 'postimagediv', 'slider', 'side' );
  135.     add_meta_box('postimagediv', __('Slideshow Images','flamingo'), 'post_thumbnail_meta_box', 'slider', 'advanced', 'default');
  136. }
  137.  
  138.  
  139. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement