Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //http://thinkvitamin.com/code/create-your-first-wordpress-custom-post-type/
- //http://wordpress.org/extend/plugins/verve-meta-boxes/screenshots/
- //http://more-plugins.se/plugins/more-types/
- add_theme_support( 'menus' );
- add_action('init', 'restaurant_register');
- function restaurant_register() {
- $labels = array(
- 'name' => _x('Restaurants', 'post type general name'),
- 'singular_name' => _x('Restaurants', 'post type singular name'),
- 'add_new' => _x('Add New', 'portfolio item'),
- 'add_new_item' => __('Add New Restaurant'),
- 'edit_item' => __('Edit Restaurant'),
- 'new_item' => __('New Restaurant'),
- 'view_item' => __('View Restaurant'),
- 'search_items' => __('Search Restaurants'),
- 'not_found' => __('Nothing found'),
- 'not_found_in_trash' => __('Nothing found in Trash'),
- 'parent_item_colon' => ''
- );
- $args = array(
- 'labels' => $labels,
- 'public' => true,
- 'publicly_queryable' => true,
- 'show_ui' => true,
- 'query_var' => true,
- //'menu_icon' => get_stylesheet_directory_uri() . '/article16.png',
- 'rewrite' => true,
- 'capability_type' => 'post',
- 'hierarchical' => false,
- 'menu_position' => null,
- 'supports' => array('title',
- //'excerpt',
- 'editor',
- //'trackbacks',
- //'custom-fields',
- //'comments',
- 'revisions',
- 'thumbnail',
- //'author',
- 'page-attributes'
- )
- );
- register_post_type( 'restaurant' , $args );
- }
- register_taxonomy("tour", array("tours", "restaurant", "reviews", "guides", "parking"), array("hierarchical" => true, "label" => "Tour Assignment", "singular_label" => "Tour", "rewrite" => true));
- add_action("admin_init", "build_custom_fields");
- function build_custom_fields(){
- //add_meta_box("reviews_meta", "Year Completed", "reviews", "restaurant", "side", "low");
- add_meta_box("reviews_meta", "Reviews", "add_reviews", "restaurant", "normal", "low");
- add_meta_box("accolades_meta", "Accolades", "add_accolades", "restaurant", "normal", "low");
- add_meta_box("details_meta", "Details", "add_details", "restaurant", "normal", "low");
- }
- function add_reviews(){
- global $post;
- $custom = get_post_custom($post->ID);
- $reviews = $custom["reviews"][0];
- ?>
- <?php wp_editor( $reviews, "reviews", $settings = array( 'textarea_rows' => '10' , 'wpautop' => true, 'tinymce' => true) ); ?>
- <?php
- }
- function add_accolades(){
- global $post;
- $custom = get_post_custom($post->ID);
- $accoldates = $custom["accolades"][0];
- ?>
- <p><label>Accolades:</label><br />
- <?php wp_editor( $accoldates, "accolades", $settings = array( 'textarea_rows' => '10', 'wpautop' => true, 'tinymce' => true) ); ?>
- <?php
- }
- function add_details() {
- global $post;
- $custom = get_post_custom($post->ID);
- $food_type = $custom["food_type"][0];
- $known_for = $custom["known_for"][0];
- $tour_includes = $custom["tour_includes"][0];
- $address = $custom["address"][0];
- $website = $custom["website"][0];
- $yelp = $custom["yelp"][0];
- $urbanspoon = $custom["urbanspoon"][0];
- ?>
- <p><label>Food:</label><br />
- <textarea cols="80" rows="1" name="food_type"><?php echo $food_type; ?></textarea></p>
- <p><label>Known For:</label><br />
- <textarea cols="80" rows="1" name="known_for"><?php echo $known_for; ?></textarea></p>
- <p><label>Food Served on Tour:</label><br />
- <textarea cols="80" rows="1" name="tour_includes"><?php echo $tour_includes; ?></textarea></p>
- <p><label>Yelp Review Link:</label><br />
- <textarea cols="80" rows="1" name="yelp"><?php echo $yelp; ?></textarea></p>
- <p><label>Urban Spoon:</label><br />
- <textarea cols="80" rows="1" name="urbanspoon"><?php echo $urbanspoon; ?></textarea></p>
- <p><label>Website:</label><br />
- <textarea cols="80" rows="1" name="website"><?php echo $website; ?></textarea></p>
- <p><label>Street Address:</label><br />
- <!-- <textarea cols="80" rows="5" name="address"><?php echo $address; ?></textarea></p> -->
- <?php wp_editor( $address, "address", $settings = array( 'textarea_rows' => '3' , 'wpautop' => false, 'tinymce' => true) ); ?>
- <?php
- }
- add_action('save_post', 'save_details');
- function save_details(){
- global $post;
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
- return $post->ID;
- }
- //wpautop()
- update_post_meta($post->ID, "theme",$_POST["theme"]);
- update_post_meta($post->ID, "highlights", $_POST["highlights"]);
- update_post_meta($post->ID, "reviews", wpautop($_POST["reviews"]));
- update_post_meta($post->ID, "food_type", $_POST["food_type"]);
- update_post_meta($post->ID, "tour_includes", $_POST["tour_includes"]);
- update_post_meta($post->ID, "known_for", $_POST["known_for"]);
- update_post_meta($post->ID, "address", wpautop($_POST["address"]));
- update_post_meta($post->ID, "website", $_POST["website"]);
- update_post_meta($post->ID, "accolades", wpautop($_POST["accolades"]));
- update_post_meta($post->ID, "yelp", $_POST["yelp"]);
- update_post_meta($post->ID, "urbanspoon", $_POST["urbanspoon"]);
- update_post_meta($post->ID, "buylink", $_POST["buylink"]);
- update_post_meta($post->ID, "slogan", $_POST["slogan"]);
- update_post_meta($post->ID, "page_quote", $_POST["page_quote"]);
- update_post_meta($post->ID, "page_quote_person", $_POST["page_quote_person"]);
- update_post_meta($post->ID, "this_season_days", $_POST["this_season_days"]);
- update_post_meta($post->ID, "next_season_days", $_POST["next_season_days"]);
- update_post_meta($post->ID, "next_season", $_POST["next_season"]);
- update_post_meta($post->ID, "times", $_POST["times"]);
- update_post_meta($post->ID, "duration", $_POST["duration"]);
- update_post_meta($post->ID, "price", $_POST["price"]);
- update_post_meta($post->ID, "start_location", $_POST["start_location"]);
- update_post_meta($post->ID, "discounts", $_POST["discounts"]);
- update_post_meta($post->ID, "parking", $_POST["parking"]);
- update_post_meta($post->ID, "map", $_POST["map"]);
- }
- add_theme_support('post-thumbnails');
- add_action('init','remove_posttype_thumbnail_support');
- function remove_posttype_thumbnail_support() {
- remove_post_type_support('page','thumbnail');
- }
- //Use "Featured Image" box as a custom box
- function customposttype_image_box() {
- remove_meta_box('postimagediv', 'restaurant', 'side');
- remove_meta_box('postimagediv', 'au-gallery', 'side');
- add_meta_box('galleryimagediv', __('Full Size Image. Ratio 4:3, minimum size 800 x 800 pixels.'), 'post_thumbnail_meta_box', 'au-gallery', 'normal', 'low');
- add_meta_box('postimagediv', __('Restaurant Logo'), 'post_thumbnail_meta_box', 'restaurant', 'side', 'low');
- }
- add_action('do_meta_boxes', 'customposttype_image_box');
- add_action('init', 'tours_register');
- function tours_register() {
- $labels = array(
- 'name' => _x('Tours', 'post type general name'),
- 'singular_name' => _x('Tours', 'post type singular name'),
- 'add_new' => _x('Add New', 'portfolio item'),
- 'add_new_item' => __('Add New Tour'),
- 'edit_item' => __('Edit Tour'),
- 'new_item' => __('New Tour'),
- 'view_item' => __('View Tours'),
- 'search_items' => __('Search Tours'),
- 'not_found' => __('Nothing found'),
- 'not_found_in_trash' => __('Nothing found in Trash'),
- 'parent_item_colon' => ''
- );
- $args = array(
- 'labels' => $labels,
- 'public' => true,
- 'publicly_queryable' => true,
- 'show_ui' => true,
- 'query_var' => true,
- //'menu_icon' => get_stylesheet_directory_uri() . '/article16.png',
- 'rewrite' => true,
- 'capability_type' => 'post',
- 'hierarchical' => false,
- 'menu_position' => null,
- 'supports' => array('title',
- 'excerpt',
- 'editor',
- //'trackbacks',
- //'custom-fields',
- //'comments',
- 'revisions',
- 'thumbnail',
- //'author',
- 'page-attributes'
- )
- );
- register_post_type( 'tours' , $args );
- }
- if (class_exists('MultiPostThumbnails')) {
- new MultiPostThumbnails(array(
- 'label' => 'Secondary Image',
- 'id' => 'secondary-image',
- 'post_type' => 'tours'
- )
- );
- }
- ////////////////////////////////////////////////////////////
- add_action("admin_init", "build_custom_tour_fields");
- function build_custom_tour_fields(){
- add_meta_box("tour_meta", "Tour Details", "add_tour_details", "tours", "normal", "low");
- }
- function add_tour_details(){
- global $post;
- $custom = get_post_custom($post->ID);
- $page_quote = $custom["page_quote"][0];
- $page_quote_person = $custom["page_quote_person"][0];
- $slogan = $custom["slogan"][0];
- $theme = $custom["theme"][0];
- $highlights = $custom["highlights"][0];
- $this_season_days = $custom["this_season_days"][0];
- $next_season_days = $custom["next_season_days"][0];
- $next_season = $custom["next_season"][0];
- $times = $custom["times"][0];
- $duration = $custom["duration"][0];
- $price = $custom["price"][0];
- $start_location = $custom["start_location"][0];
- $discounts = $custom["discounts"][0];
- $parking = $custom["parking"][0];
- $map = $custom["map"][0];
- $buylink = $custom["buylink"][0];
- ?>
- <p><label>Page Quote: (This is the quote at the top of the page)</label><br />
- <textarea cols="80" rows="1" name="page_quote"><?php echo $page_quote; ?></textarea></p>
- <p><label>Page Quote Person: (This is the person that said the quote at the top of the page)</label><br />
- <textarea cols="80" rows="1" name="page_quote_person"><?php echo $page_quote_person; ?></textarea></p>
- <p><label>Tour Slogan: (This goes over the main image on the tour page)</label><br />
- <textarea cols="80" rows="1" name="slogan"><?php echo $slogan; ?></textarea></p>
- <p><label>Theme: (Eclectic tastes and cultural history)</label><br />
- <textarea cols="80" rows="1" name="theme"><?php echo $theme; ?></textarea></p>
- <p><label>Highlights: (Taste off menu of James Beard winning chef paired with glass of wine)</label><br />
- <textarea cols="80" rows="1" name="highlights"><?php echo $highlights; ?></textarea></p>
- <p><label>This Season Days (Thurs. thru Sat. )</label><br />
- <textarea cols="80" rows="1" name="this_season_days"><?php echo $this_season_days; ?></textarea></p>
- <p><label>Next Season Months (Nov. thru March):</label><br />
- <textarea cols="80" rows="1" name="next_season"><?php echo $next_season; ?></textarea></p>
- <p><label>Next Season Days ( )</label><br />
- <textarea cols="80" rows="1" name="next_season_days"><?php echo $next_season_days; ?></textarea></p>
- <p><label>Buy tickets Link: (http://my.getinsellout.com/providers/20214/skus/26105/book)</label><br />
- <textarea cols="80" rows="1" name="buylink"><?php echo $buylink; ?></textarea></p>
- <p><label>Tour lasts between these hours (4pm-7pm):</label><br />
- <textarea cols="80" rows="1" name="times"><?php echo $times; ?></textarea></p>
- <p><label>Tour Duration (3hrs):</label><br />
- <textarea cols="80" rows="1" name="duration"><?php echo $duration; ?></textarea></p>
- <p><label>Tour Price ($69 per person):</label><br />
- <textarea cols="80" rows="1" name="price"><?php echo $price; ?></textarea></p>
- <p><label>Tour Meeting Location (Near 1st Ave.)</label><br />
- <textarea cols="80" rows="1" name="start_location"><?php echo $start_location; ?></textarea></p>
- <p><label>Discounts from taking tour:</label><br />
- <textarea cols="80" rows="1" name="discounts"><?php echo $discounts; ?></textarea></p>
- <p><label>Where to park:</label><br />
- <textarea cols="80" rows="1" name="parking"><?php echo $parking; ?></textarea></p>
- <p><label>Google Embedded map (map url):</label><br />
- <textarea cols="80" rows="10" name="map"><?php echo $map; ?></textarea></p>
- <?php //wp_editor( $reviews, "map", $settings = array( 'textarea_rows' => '10' ) ); ?>
- <?php
- }
- //////////////////////////////////////////////////////
- add_action("admin_init", "build_custom_page_fields");
- function build_custom_page_fields(){
- add_meta_box("page_meta", "Page Details", "add_page_details", "page", "normal", "low");
- }
- function add_page_details(){
- global $post;
- $custom = get_post_custom($post->ID);
- $page_quote = $custom["page_quote"][0];
- $page_quote_person = $custom["page_quote_person"][0];
- ?>
- <p><label>Page Quote: (This is the quote at the top of the page)</label><br />
- <textarea cols="80" rows="1" name="page_quote"><?php echo $page_quote; ?></textarea></p>
- <p><label>Page Quote Person: (This is the person that said the quote at the top of the page)</label><br />
- <textarea cols="80" rows="1" name="page_quote_person"><?php echo $page_quote_person; ?></textarea></p>
- <?php
- }
- ////////////////////////////////////////////////
- add_action('init', 'guides_register');
- function guides_register() {
- $labels = array(
- 'name' => _x('Guides', 'post type general name'),
- 'singular_name' => _x('Guides', 'post type singular name'),
- 'add_new' => _x('Add New', 'portfolio item'),
- 'add_new_item' => __('Add New Guide'),
- 'edit_item' => __('Edit Guide'),
- 'new_item' => __('New Guide'),
- 'view_item' => __('View Guides'),
- 'search_items' => __('Search Guides'),
- 'not_found' => __('Nothing found'),
- 'not_found_in_trash' => __('Nothing found in Trash'),
- 'parent_item_colon' => ''
- );
- $args = array(
- 'labels' => $labels,
- 'public' => true,
- 'publicly_queryable' => true,
- 'show_ui' => true,
- 'query_var' => true,
- //'menu_icon' => get_stylesheet_directory_uri() . '/article16.png',
- 'rewrite' => true,
- 'capability_type' => 'post',
- 'hierarchical' => false,
- 'menu_position' => null,
- 'supports' => array('title',
- //'excerpt',
- 'editor',
- //'trackbacks',
- //'custom-fields',
- //'comments',
- 'revisions',
- 'thumbnail',
- //'author',
- 'page-attributes'
- )
- );
- register_post_type( 'guides' , $args );
- }
- add_action('init', 'reviews_register');
- function reviews_register() {
- $labels = array(
- 'name' => _x('Tour Reviews', 'post type general name'),
- 'singular_name' => _x('Reviews', 'post type singular name'),
- 'add_new' => _x('Add New', 'portfolio item'),
- 'add_new_item' => __('Add New Review'),
- 'edit_item' => __('Edit Review'),
- 'new_item' => __('New Review'),
- 'view_item' => __('View Reviews'),
- 'search_items' => __('Search Reviews'),
- 'not_found' => __('Nothing found'),
- 'not_found_in_trash' => __('Nothing found in Trash'),
- 'parent_item_colon' => ''
- );
- $args = array(
- 'labels' => $labels,
- 'public' => true,
- 'publicly_queryable' => true,
- 'show_ui' => true,
- 'query_var' => true,
- //'menu_icon' => get_stylesheet_directory_uri() . '/article16.png',
- 'rewrite' => true,
- 'capability_type' => 'post',
- 'hierarchical' => false,
- 'menu_position' => null,
- 'supports' => array('title',
- //'excerpt',
- 'editor',
- //'trackbacks',
- //'custom-fields',
- //'comments',
- 'revisions',
- 'thumbnail',
- //'author',
- 'page-attributes'
- )
- );
- register_post_type( 'reviews' , $args );
- //register_taxonomy("Tour", array("reviews"), array("hierarchical" => true, "label" => "Tours", "singular_label" => "Tour", "rewrite" => true));
- }
- ////////////////////////////////////////////////////////
- function attachments_get_attachments_alt ( $post_id=null, $class=null)
- {
- global $post;
- if( $post_id==null )
- {
- $post_id = $post->ID;
- }
- // get all attachments
- $existing_attachments = get_post_meta( $post_id, '_attachments', false );
- // We can now proceed as normal, all legacy data should now be upgraded
- $post_attachments = array();
- if( is_array( $existing_attachments ) && count( $existing_attachments ) > 0 )
- {
- foreach ($existing_attachments as $attachment)
- {
- // decode and unserialize the data
- $data = unserialize( base64_decode( $attachment ) );
- array_push( $post_attachments, array(
- 'id' => stripslashes( $data['id'] ),
- 'name' => stripslashes( get_the_title( $data['id'] ) ),
- 'mime' => stripslashes( get_post_mime_type( $data['id'] ) ),
- 'title' => stripslashes( $data['title'] ),
- 'caption' => stripslashes( $data['caption'] ),
- 'location' => stripslashes( wp_get_attachment_url( $data['id'] ) ),
- 'order' => stripslashes( $data['order'] ),
- 'gallery-main-src' => stripslashes( getSRC($data['id'], 'gallery-main') ) ,
- 'gallery-thumbnail-src' => stripslashes( getSRC($data['id'], 'gallery-thumbnail') ) ,
- 'thumbnail-src' => stripslashes( getSRC($data['id'], 'thumbnail') ) ,
- 'medium-src' => stripslashes( getSRC($data['id'], 'medium') ) ,
- 'large-src' => stripslashes( getSRC($data['id'], 'large') ) ,
- 'full-src' => stripslashes( getSRC($data['id'], 'full') ) ,
- 'thumbnail' => stripslashes( wp_get_attachment_image( $data['id'], 'thumbnail', array('class' => $class) ) ),
- 'medium' => stripslashes( wp_get_attachment_image( $data['id'], 'medium', array('class' => $class) ) ),
- 'large' => stripslashes( wp_get_attachment_image( $data['id'], 'large', array('class' => $class) ) ),
- 'full' => stripslashes( wp_get_attachment_image( $data['id'], 'full', array('class' => $class) ) )
- ));
- }
- // sort attachments
- if( count( $post_attachments ) > 1 )
- {
- }
- }
- return $post_attachments;
- }
- function getSRC ($id, $size) {
- $arr = wp_get_attachment_image_src($id, $size);
- return $arr[0];
- }
- add_action( 'widgets_init', 'my_register_sidebars' );
- function my_register_sidebars() {
- register_sidebar(
- array(
- 'id' => 'primary',
- 'name' => __( 'Primary' ),
- 'before_widget' => '<div id="%1$s" class="widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h3 class="widget-title">',
- 'after_title' => '</h3>'
- )
- );
- }
- ///////////////////////////////////////////////////
- add_action('init', 'restaurant_parking');
- function restaurant_parking() {
- $labels = array(
- 'name' => _x('Parking Lots', 'post type general name'),
- 'singular_name' => _x('Parking Lots', 'post type singular name'),
- 'add_new' => _x('Add New', 'portfolio item'),
- 'add_new_item' => __('Add New Parking Lot'),
- 'edit_item' => __('Edit Parking Lot'),
- 'new_item' => __('New Parking Lot'),
- 'view_item' => __('View Parking Lots'),
- 'search_items' => __('Search Parking Lots'),
- 'not_found' => __('Nothing found'),
- 'not_found_in_trash' => __('Nothing found in Trash'),
- 'parent_item_colon' => ''
- );
- $args = array(
- 'labels' => $labels,
- 'public' => true,
- 'publicly_queryable' => true,
- 'show_ui' => true,
- 'query_var' => true,
- //'menu_icon' => get_stylesheet_directory_uri() . '/article16.png',
- 'rewrite' => true,
- 'capability_type' => 'post',
- 'hierarchical' => false,
- 'menu_position' => null,
- 'supports' => array('title',
- //'excerpt',
- 'editor',
- //'trackbacks',
- //'custom-fields',
- //'comments',
- 'revisions',
- //'thumbnail',
- //'author',
- 'page-attributes'
- )
- );
- register_post_type( 'parking' , $args );
- }
- add_image_size( 'logo-thumbnail', '70', '70', true );
- add_image_size( 'logo-display', '120', '120', false );
- add_image_size( 'logo-full', '150', '150', false );
- add_image_size( 'gallery-main', '260', '185', false );
- add_image_size( 'gallery-thumbnail', '60', '45', false );
- add_image_size( 'headshot', '100', '115', true );
- function the_parent_category_link($text = "back", $selector = true)
- {
- global $post;
- if ( !isset($post->post_category) ) {
- return;
- }
- $url = get_settings('siteurl').'/cat='.$post->post_category;
- if(!$selector) {
- return $url;
- }
- else {
- echo '<a href="'.$url.'">'.$text.'</a>';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement