Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- //
- // Custom Post Type: Projects
- //
- */
- /* ------ [ Project Post Type ] ------ */
- register_post_type(
- 'project',
- array(
- 'label' => 'Projects',
- 'description' => 'Project Portfolio',
- 'public' => true,
- 'show_ui' => true,
- 'show_in_menu' => true,
- 'capability_type' => 'post',
- 'hierarchical' => false,
- 'rewrite' => false,
- 'menu_position' => 5,
- 'publicly_queryable' => true,
- 'query_var' => true,
- 'supports' => array(
- 'title',
- 'editor'
- ),
- 'labels' => array (
- 'name' => 'Project',
- 'singular_name' => 'Project',
- 'menu_name' => 'Project List',
- 'add_new' => 'Add Project',
- 'add_new_item' => 'Add Project',
- 'edit' => 'Edit Projects',
- 'edit_item' => 'Edit Project',
- 'new_item' => 'New Project',
- 'view' => 'View Projects',
- 'view_item' => 'View Project',
- 'search_items' => 'Search Projects',
- 'not_found' => 'No Projects Found',
- 'not_found_in_trash' => 'No Projects in Trash',
- 'parent' => 'Parent Project'
- )
- )
- );
- global $wp_rewrite;
- $project_structure = '/portfolio/%project%';
- $wp_rewrite->add_rewrite_tag("%project%", '([^/]+)', "project=");
- $wp_rewrite->add_permastruct('project', $project_structure, false);
- /* ------ [ Project Metaboxes ] ------ */
- add_filter( 'cmb_meta_boxes', 'cmb_my_metaboxes' );
- function cmb_my_metaboxes(array $meta_boxes){
- $prefix = 'project_';
- $meta_boxes[] = array(
- 'id' => 'project_details',
- 'title' => 'Project Details',
- 'pages' => array('project',), // post type
- 'context' => 'normal',
- 'priority' => 'high',
- 'show_names' => true, // Show field names on the left
- 'fields' => array(
- array(
- 'name' => 'Client',
- 'desc' => 'Client(s) name',
- 'id' => $prefix . 'client',
- 'type' => 'text_medium',
- ),
- array(
- 'name' => 'Client url',
- 'desc' => 'Website for the client',
- 'id' => $prefix . 'client_url',
- 'type' => 'text_medium',
- ),
- array(
- 'name' => 'Architect',
- 'desc' => 'Architect or Secondary Client',
- 'id' => $prefix . 'architect',
- 'type' => 'text_medium',
- ),
- array(
- 'name' => 'Architect url',
- 'desc' => 'Website for the architect',
- 'id' => $prefix . 'architect_url',
- 'type' => 'text_medium',
- ),
- array(
- 'name' => 'Project Location',
- 'desc' => 'City, State',
- 'id' => $prefix . 'location',
- 'type' => 'text_medium',
- ),
- array(
- 'name' => 'Featured Photo',
- 'id' => $prefix . 'featured_image',
- 'desc' => 'Attach image file (jpg, png, gif)',
- 'type' => 'file',
- 'allow' => array( 'url', 'attachment' ),
- ),
- array(
- 'name' => 'Date',
- 'desc' => 'Project completion date',
- 'id' => $prefix . 'date',
- 'type' => 'text_date',
- ),
- array(
- 'name' => 'Additional Project Photos',
- 'desc' => 'List of photos for project gallery',
- 'id' => $prefix . 'photo_list',
- 'type' => 'file_list',
- ),
- array(
- 'name' => 'Short Description',
- 'desc' => 'Display on portfolio page, limit to 200 words',
- 'id' => $prefix . 'short_description',
- 'type' => 'textarea_small',
- ),
- )
- );
- /* ------ [ Project Long Bio ] ------ */
- $meta_boxes[] = array(
- 'id' => 'project_description',
- 'title' => 'Project Description',
- 'pages' => array('project'), // post type
- 'context' => 'normal',
- 'priority' => 'high',
- 'show_names' => true, // Show field names left of input
- 'fields' => array( )
- );
- /* ------ [ Associated Project Type to Page ] ------ */
- $meta_boxes[] = array(
- 'id' => 'page_project_type',
- 'title' => 'Attached Project Gallery',
- 'pages' => array('page'), // post type
- 'context' => 'normal',
- 'priority' => 'high',
- 'show_names' => true, // Show field names left of input
- 'fields' => array(
- array(
- 'name' => 'Associated Project Type',
- 'desc' => 'Project Type gallery that will display on this page',
- 'id' => 'page_assoc_project_type',
- 'taxonomy' => 'project_type', //Enter Taxonomy Slug
- 'type' => 'taxonomy_multicheck',
- ),
- )
- );
- return $meta_boxes;
- }
- /* ------ [ Move Post Editor Into Long Description for Project Post Type ] ------ */
- function project_move_posteditor( $hook ) {
- if ( $hook == 'post.php' OR $hook == 'post-new.php' ) {
- wp_enqueue_script( 'jquery' );
- add_action('admin_print_footer_scripts','project_move_posteditor_scripts');
- }
- }
- add_action( 'admin_enqueue_scripts', 'project_move_posteditor', 10, 1 );
- function project_move_posteditor_scripts() {
- ?>
- <script type="text/javascript">
- jQuery('#postdiv, #postdivrich').prependTo('#project_description .inside');
- </script>
- <style type="text/css">
- #normal-sortables {margin-top: 20px;}
- #titlediv { margin-bottom: 0px; }
- #postdiv.postarea, #postdivrich.postarea { margin:0; }
- #post-status-info { line-height:1.4em; font-size:13px; }
- #custom_editor .inside { margin:2px 6px 6px 6px; }
- #ed_toolbar { display:none; }
- #postdiv #ed_toolbar, #postdivrich #ed_toolbar { display:block; }
- </style>
- <?php
- }
- /* ------ [ Rename Post Box Title Text ] ------ */
- add_action( 'gettext', 'project_change_title_text' );
- function project_change_title_text( $translation ) {
- global $post;
- if( isset( $post ) ) {
- switch( $post->post_type ){
- case 'project' :
- if( $translation == 'Enter title here' ) return 'Enter Project Name Here';
- break;
- }
- }
- return $translation;
- }
- /* ------ [ Adding Custom Columns in Project Admin Screen ] ------ */
- function add_new_project_columns($project_columns) {
- $new_columns['cb'] = '<input type="checkbox" />';
- $new_columns['title'] = _x('Project Name', 'column name');
- $new_columns['desc'] = __('Short Description');
- $new_columns['type'] = __('Project Types');
- return $new_columns;
- }
- function manage_project_columns($column_name, $id) {
- global $typenow;
- global $post;
- if ($typenow=='project') {
- $taxonomy = 'project_type';
- switch ($column_name) {
- case 'type':
- $types = get_the_terms( $post->ID ,$taxonomy);
- if (is_array($types )) {
- foreach($types as $key => $type ) {
- $edit_link = get_term_link( $type, $taxonomy );
- $term = get_term( $type, $taxonomy );
- $slug = $term->slug;
- $types[$key] = '<a href="edit.php?'.$taxonomy.'='.$slug.'&post_type='.$typenow.'">' . $type->name . '</a>';
- }
- //echo implode("<br/>",$businesses);
- echo implode(' | ',$types);
- }
- break;
- case 'desc':
- echo get_post_meta( $post->ID, 'project_short_description', TRUE);
- break;
- default:
- break;
- } // end switch
- }
- }
- add_filter('manage_edit-project_columns', 'add_new_project_columns');
- add_action('manage_project_posts_custom_column', 'manage_project_columns', 10, 2);
- /* ------ [ Project Type Taxonomy ] ------ */
- function dcg_register_project_type_taxonomy() {
- $labels = array(
- 'name' => 'Project Type',
- 'singular_name' => 'Project Type',
- 'search_items' => 'Search Project Types',
- 'all_items' => 'All Project Types',
- 'edit_item' => 'Edit Project Type',
- 'update_item' => 'Update Project Type',
- 'add_new_item' => 'Add New Project Type',
- 'new_item_name' => 'New Project Type Name',
- 'menu_name' => 'Project Types'
- );
- register_taxonomy( 'project_type', array('project'),
- array(
- 'hierarchical' => true,
- 'labels' => $labels,
- 'show_ui' => true,
- 'query_var' => true,
- 'rewrite' => array( 'slug' => 'project_type' ),
- )
- );
- }
- add_action( 'init', 'dcg_register_project_type_taxonomy',1 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement