Advertisement
jasonday

canvas/wp-listings

Dec 10th, 2014
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.17 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Single Post Template
  4.  *
  5.  * This template is the default page template. It is used to display content when someone is viewing a
  6.  * singular view of a post ('post' post_type).
  7.  * @link http://codex.wordpress.org/Post_Types#Post
  8.  *
  9.  * @package WooFramework
  10.  * @subpackage Template
  11.  */
  12.  
  13.  
  14.  
  15. get_header();
  16.  
  17. function single_listing_assets() {
  18.    wp_enqueue_style( 'single-listing',  'http://www.mysite.com/wp-content/plugins/wp-listings/includes/css/wp-listings-single.css' );
  19. }
  20. add_action( 'wp_enqueue_scripts', 'single_listing_assets' );
  21. /* property */
  22.  
  23. function single_listing_post_content() {
  24.  
  25.     global $post;
  26.  
  27.     ?>
  28.  
  29.     <div class="entry-content wplistings-single-listing">
  30.  
  31.         <div class="listing-image-wrap">
  32.             <?php echo get_the_post_thumbnail( $post->ID, 'listings-full', array('class' => 'single-listing-image') );
  33.             if ( '' != wp_listings_get_status() ) {
  34.                 printf( '<span class="listing-status %s">%s</span>', strtolower(str_replace(' ', '-', wp_listings_get_status())), wp_listings_get_status() );
  35.             }
  36.             if ( '' != get_post_meta( $post->ID, '_listing_open_house', true ) ) {
  37.                 printf( '<span class="listing-open-house">Open House: %s</span>', get_post_meta( $post->ID, '_listing_open_house', true ) );
  38.             } ?>
  39.         </div><!-- .listing-image-wrap -->
  40.  
  41.         <?php
  42.         $listing_meta = sprintf( '<ul class="listing-meta">');
  43.  
  44.         if ( '' != get_post_meta( $post->ID, '_listing_price', true ) ) {
  45.             $listing_meta .= sprintf( '<li class="listing-price">%s</li>', get_post_meta( $post->ID, '_listing_price', true ) );
  46.         }
  47.  
  48.         if ( '' != wp_listings_get_property_types() ) {
  49.             $listing_meta .= sprintf( '<li class="listing-property-type"><span class="label">Property Type: </span>%s</li>', get_the_term_list( get_the_ID(), 'property-types', '', ', ', '' ) );
  50.         }
  51.  
  52.         if ( '' != wp_listings_get_locations() ) {
  53.             $listing_meta .= sprintf( '<li class="listing-location"><span class="label">Location: </span>%s</li>', get_the_term_list( get_the_ID(), 'locations', '', ', ', '' ) );
  54.         }
  55.  
  56.         if ( '' != get_post_meta( $post->ID, '_listing_bedrooms', true ) ) {
  57.             $listing_meta .= sprintf( '<li class="listing-bedrooms"><span class="label">Beds: </span>%s</li>', get_post_meta( $post->ID, '_listing_bedrooms', true ) );
  58.         }
  59.  
  60.         if ( '' != get_post_meta( $post->ID, '_listing_bathrooms', true ) ) {
  61.             $listing_meta .= sprintf( '<li class="listing-bathrooms"><span class="label">Baths: </span>%s</li>', get_post_meta( $post->ID, '_listing_bathrooms', true ) );
  62.         }
  63.  
  64.         if ( '' != get_post_meta( $post->ID, '_listing_sqft', true ) ) {
  65.             $listing_meta .= sprintf( '<li class="listing-sqft"><span class="label">Sq Ft: </span>%s</li>', get_post_meta( $post->ID, '_listing_sqft', true ) );
  66.         }
  67.  
  68.         if ( '' != get_post_meta( $post->ID, '_listing_lot_sqft', true ) ) {
  69.             $listing_meta .= sprintf( '<li class="listing-lot-sqft"><span class="label">Lot Sq Ft: </span>%s</li>', get_post_meta( $post->ID, '_listing_lot_sqft', true ) );
  70.         }
  71.  
  72.         $listing_meta .= sprintf( '</ul>');
  73.  
  74.         echo $listing_meta;
  75.  
  76.         ?>
  77.  
  78.         <div id="listing-tabs" class="listing-data">
  79.  
  80.             <ul>
  81.                 <li><a href="#listing-description">Description</a></li>
  82.  
  83.                 <li><a href="#listing-details">Details</a></li>
  84.  
  85.  
  86.                 <?php if (get_post_meta( $post->ID, '_listing_gallery', true) != '') { ?>
  87.                     <li><a href="#listing-gallery">Photos</a></li>
  88.                 <?php } ?>
  89.  
  90.                 <?php if (get_post_meta( $post->ID, '_listing_video', true) != '') { ?>
  91.                     <li><a href="#listing-video">Video / Virtual Tour</a></li>
  92.                 <?php } ?>
  93.  
  94.                 <?php if (get_post_meta( $post->ID, '_listing_school_neighborhood', true) != '') { ?>
  95.                 <li><a href="#listing-school-neighborhood">Schools &amp; Neighborhood</a></li>
  96.                 <?php } ?>
  97.             </ul>
  98.  
  99.             <div id="listing-description">
  100.                 <?php the_content( __( 'View more <span class="meta-nav">&rarr;</span>', 'wp_listings' ) ); ?>
  101.             </div><!-- #listing-description -->
  102.  
  103.             <div id="listing-details">
  104.                 <?php
  105.                     $details_instance = new WP_Listings();
  106.  
  107.                     $pattern = '<tr class="wp_listings%s"><td class="label">%s</td><td>%s</td></tr>';
  108.  
  109.                     echo '<table class="listing-details">';
  110.  
  111.                     echo '<tbody class="left">';
  112.                     foreach ( (array) $details_instance->property_details['col1'] as $label => $key ) {
  113.                         $detail_value = esc_html( get_post_meta($post->ID, $key, true) );
  114.                         if (! empty( $detail_value ) ) :
  115.                             printf( $pattern, $key, esc_html( $label ), $detail_value );
  116.                         endif;
  117.                     }
  118.                     echo '</tbody>';
  119.  
  120.                     echo '<tbody class="right">';
  121.                     foreach ( (array) $details_instance->property_details['col2'] as $label => $key ) {
  122.                         $detail_value = esc_html( get_post_meta($post->ID, $key, true) );
  123.                         if (! empty( $detail_value ) ) :
  124.                             printf( $pattern, $key, esc_html( $label ), $detail_value );
  125.                         endif;
  126.                     }
  127.                     echo '</tbody>';
  128.  
  129.                     echo '</table>';
  130.  
  131.                 echo '<h5>Tagged Features</h5><ul class="tagged-features">';
  132.                 echo get_the_term_list( get_the_ID(), 'features', '<li>', '</li><li>', '</li>' );
  133.                 echo '</ul><!-- .tagged-features -->';
  134.  
  135.                 if ( get_post_meta( $post->ID, '_listing_home_sum', true) != '' || get_post_meta( $post->ID, '_listing_kitchen_sum', true) != '' || get_post_meta( $post->ID, '_listing_living_room', true) != '' || get_post_meta( $post->ID, '_listing_master_suite', true) != '') { ?>
  136.                     <div class="additional-features">
  137.                         <h4>Additional Features</h4>
  138.                         <h6 class="label"><?php _e("Home Summary", 'wp_listings'); ?></h6>
  139.                         <p class="value"><?php echo do_shortcode(get_post_meta( $post->ID, '_listing_home_sum', true)); ?></p>
  140.                         <h6 class="label"><?php _e("Kitchen Summary", 'wp_listings'); ?></h6>
  141.                         <p class="value"><?php echo do_shortcode(get_post_meta( $post->ID, '_listing_kitchen_sum', true)); ?></p>
  142.                         <h6 class="label"><?php _e("Living Room", 'wp_listings'); ?></h6>
  143.                         <p class="value"><?php echo do_shortcode(get_post_meta( $post->ID, '_listing_living_room', true)); ?></p>
  144.                         <h6 class="label"><?php _e("Master Suite", 'wp_listings'); ?></h6>
  145.                         <p class="value"><?php echo do_shortcode(get_post_meta( $post->ID, '_listing_master_suite', true)); ?></p>
  146.                     </div><!-- .additional-features -->
  147.                 <?php
  148.                 } ?>               
  149.  
  150.             </div><!-- #listing-details -->
  151.  
  152.             <?php if (get_post_meta( $post->ID, '_listing_gallery', true) != '') { ?>
  153.             <div id="listing-gallery">
  154.                 <?php echo do_shortcode(get_post_meta( $post->ID, '_listing_gallery', true)); ?>
  155.             </div><!-- #listing-gallery -->
  156.             <?php } ?>
  157.  
  158.             <?php if (get_post_meta( $post->ID, '_listing_video', true) != '') { ?>
  159.             <div id="listing-video">
  160.                 <div class="iframe-wrap">
  161.                 <?php echo get_post_meta( $post->ID, '_listing_video', true); ?>
  162.                 </div>
  163.             </div><!-- #listing-video -->
  164.             <?php } ?>
  165.  
  166.             <?php if (get_post_meta( $post->ID, '_listing_school_neighborhood', true) != '') { ?>
  167.             <div id="listing-school-neighborhood">
  168.                 <p>
  169.                 <?php echo do_shortcode(get_post_meta( $post->ID, '_listing_school_neighborhood', true)); ?>
  170.                 </p>
  171.             </div><!-- #listing-school-neighborhood -->
  172.             <?php } ?>
  173.  
  174.         </div><!-- #listing-tabs.listing-data -->
  175.  
  176.         <?php
  177.             if (get_post_meta( $post->ID, '_listing_map', true) != '') {
  178.             echo '<div id="listing-map"><h3>Location Map</h3>';
  179.             echo do_shortcode(get_post_meta( $post->ID, '_listing_map', true) );
  180.             echo '</div><!-- .listing-map -->';
  181.             }
  182.         ?>
  183.  
  184.         <?php
  185.             if (function_exists('_p2p_init') && function_exists('agent_profiles_init') ) {
  186.                 echo'<div id="listing-agent">
  187.                 <div class="connected-agents">';
  188.                 aeprofiles_connected_agents_markup();
  189.                 echo '</div></div><!-- .listing-agent -->';
  190.             }
  191.         ?>
  192.  
  193.         <div id="listing-contact" <?php if(!function_exists('aeprofiles_connected_agents_markup')) { echo 'style="width: 100%;"'; }; ?>>
  194.             <h4>Listing Inquiry</h4>
  195.             <?php
  196.             if (get_post_meta( $post->ID, '_listing_contact_form', true) != '') {
  197.  
  198.                 echo do_shortcode(get_post_meta( $post->ID, '_listing_contact_form', true) );
  199.  
  200.             } else {
  201.  
  202.                 $nameError = '';
  203.                 $emailError = '';
  204.  
  205.                 if(isset($_POST['submitted'])) {
  206.  
  207.                 $url = get_permalink();
  208.                 $listing = get_the_title();
  209.  
  210.                 if(trim($_POST['contactName']) === '') {
  211.                     $nameError = 'Please enter your name.';
  212.                     $hasError = true;
  213.                 } else {
  214.                     $name = trim($_POST['contactName']);
  215.                 }
  216.  
  217.                 if(trim($_POST['email']) === '')  {
  218.                     $emailError = 'Please enter your email address.';
  219.                     $hasError = true;
  220.                 } else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) {
  221.                     $emailError = 'You entered an invalid email address.';
  222.                     $hasError = true;
  223.                 } else {
  224.                     $email = trim($_POST['email']);
  225.                 }
  226.  
  227.                 $phone = trim($_POST['phone']);
  228.  
  229.                 if(function_exists('stripslashes')) {
  230.                     $comments = stripslashes(trim($_POST['comments']));
  231.                 } else {
  232.                     $comments = trim($_POST['comments']);
  233.                 }
  234.  
  235.  
  236.                 if(!isset($hasError)) {
  237.                     $emailTo = get_the_author_meta( 'user_email', $post->post_author );
  238.                     if (!isset($emailTo) || ($emailTo == '') ){
  239.                         $emailTo = get_option('admin_email');
  240.                     }
  241.                     $subject = 'Listing Inquiry from '.$name;
  242.                     $body = "Name: $name \n\nEmail: $email \n\nPhone: $phone \n\nListing: $listing \n\nURL: $url \n\nComments: $comments";
  243.                     $headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
  244.  
  245.                     wp_mail($emailTo, $subject, $body, $headers);
  246.                     $emailSent = true;
  247.                 }
  248.  
  249.             } ?>
  250.  
  251.             <?php if(isset($emailSent) && $emailSent == true) { ?>
  252.                 <div class="thanks">
  253.                     <a name="redirectTo"></a>
  254.                     <p>Thanks, your email was sent! We'll be in touch shortly.</p>
  255.                 </div>
  256.             <?php } else { ?>
  257.                 <?php if(isset($hasError)) { ?>
  258.                     <a name="redirectTo"></a>
  259.                     <label class="error" name="redirectTo">Sorry, an error occured. Please try again.<label>
  260.                 <?php } ?>
  261.  
  262.                 <form action="<?php the_permalink(); ?>#redirectTo" id="inquiry-form" method="post">
  263.                     <ul class="inquiry-form">
  264.                         <li class="contactName">
  265.                             <label for="contactName">Name: <span class="required">*</span></label>
  266.                             <input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="required requiredField" />
  267.                             <?php if($nameError != '') { ?>
  268.                                 <label class="error"><?=$nameError;?></label>
  269.                             <?php } ?>
  270.                         </li>
  271.  
  272.                         <li class="contactEmail">
  273.                             <label for="email">Email: <span class="required">*</span></label>
  274.                             <input type="text" name="email" id="email" value="<?php if(isset($_POST['email']))  echo $_POST['email'];?>" class="required requiredField email" />
  275.                             <?php if($emailError != '') { ?>
  276.                                 <label class="error"><?=$emailError;?></label>
  277.                             <?php } ?>
  278.                         </li>
  279.  
  280.                         <li class="contactPhone">
  281.                             <label for="phone">Phone:</label>
  282.                             <input type="text" name="phone" id="phone" value="<?php if(isset($_POST['phone']))  echo $_POST['phone'];?>" />
  283.                         </li>
  284.  
  285.                         <li class="contactComments"><label for="commentsText">Message:</label>
  286.                             <textarea name="comments" id="commentsText" rows="6" cols="20"><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?></textarea>
  287.                         </li>
  288.  
  289.                         <li>
  290.                             <input id="submit" type="submit" value="Send Inquiry"></input>
  291.                         </li>
  292.                     </ul>
  293.                     <input type="hidden" name="submitted" id="submitted" value="true" />
  294.                 </form>
  295.             <?php }
  296.  
  297.             }
  298.             ?>
  299.         </div><!-- .listing-contact -->
  300.  
  301.     </div><!-- .entry-content -->
  302.  
  303. <?php
  304. }
  305.  
  306. /* end property */
  307. ?>
  308.        
  309.     <!-- #content Starts -->
  310.     <?php woo_content_before(); ?>
  311.     <div id="content" class="col-full wplistings-single-listing">
  312.    
  313.         <div id="main-sidebar-container">    
  314.  
  315.             <!-- #main Starts -->
  316.             <?php woo_main_before(); ?>
  317.             <section id="main">                      
  318. <?php
  319.     woo_loop_before();
  320.    
  321.     single_listing_post_content();
  322.    
  323.     woo_loop_after();
  324. ?>    
  325.             </section><!-- /#main -->
  326.             <?php woo_main_after(); ?>
  327.    
  328.             <?php get_sidebar(); ?>
  329.  
  330.         </div><!-- /#main-sidebar-container -->        
  331.  
  332.         <?php get_sidebar('alt'); ?>
  333.  
  334.     </div><!-- /#content -->
  335.     <?php woo_content_after(); ?>
  336.  
  337. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement