/** * The template for displaying Listing Archive pages * * @link http://codex.wordpress.org/Template_Hierarchy * * @package WP Listings * @since 0.1.0 */ function archive_listing_loop() { global $post; $count = 0; // start counter at 0 // Uncomment to use term image in your theme // echo '<div class="wp-listings-term-image">' . wp_listings_term_image(get_queried_object()->term_id, true, 'full') . '</div>'; // Start the Loop. while (have_posts()) { the_post(); $count++; // add 1 to counter on each loop $first = $count == 1 ? 'first' : ''; // if counter is 1 add class of first $loop = sprintf('<div class="listing-widget-thumb"><a href="%s" class="listing-image-link">%s</a>', get_permalink(), get_the_post_thumbnail($post->ID, 'listings')); if ('' != wp_listings_get_status()) { $loop .= sprintf('<span class="listing-status %s">%s</span>', strtolower(str_replace(' ', '-', wp_listings_get_status($post->ID, 1))), wp_listings_get_status()); } $loop .= sprintf('<div class="listing-thumb-meta">'); if ('' != get_post_meta($post->ID, '_listing_text', true)) { $loop .= sprintf('<span class="listing-text">%s</span>', get_post_meta($post->ID, '_listing_text', true)); } elseif ('' != wp_listings_get_property_types()) { $loop .= sprintf('<span class="listing-property-type">%s</span>', wp_listings_get_property_types()); } if ('' != get_post_meta($post->ID, '_listing_price', true)) { $loop .= sprintf('<span class="listing-price">%s</span>', get_post_meta($post->ID, '_listing_price', true)); } $loop .= sprintf('</div><!-- .listing-thumb-meta --></div><!-- .listing-widget-thumb -->'); if ('' != get_post_meta($post->ID, '_listing_open_house', true)) { $loop .= sprintf('<span class="listing-open-house">Open House: %s</span>', get_post_meta($post->ID, '_listing_open_house', true)); } $loop .= sprintf('<div class="listing-widget-details"><h3 class="listing-title"><a href="%s">%s</a></h3>', get_permalink(), get_the_title()); $loop .= sprintf('<p class="listing-address"><span class="listing-address">%s</span><br />', wp_listings_get_address()); $loop .= sprintf('<span class="listing-city-state-zip">%s, %s %s</span></p>', wp_listings_get_city(), wp_listings_get_state(), get_post_meta($post->ID, '_listing_zip', true)); if ('' != get_post_meta($post->ID, '_listing_bedrooms', true) || '' != get_post_meta($post->ID, '_listing_bathrooms', true) || '' != get_post_meta($post->ID, '_listing_sqft', true)) { $loop .= sprintf('<ul class="listing-beds-baths-sqft"><li class="beds">%s<span>Beds</span></li> <li class="baths">%s<span>Baths</span></li> <li class="sqft">%s<span>Sq ft</span></li></ul>', get_post_meta($post->ID, '_listing_bedrooms', true), get_post_meta($post->ID, '_listing_bathrooms', true), get_post_meta($post->ID, '_listing_sqft', true)); } $loop .= sprintf('</div><!-- .listing-widget-details -->'); $loop .= sprintf('<a href="%s" class="button btn-primary more-link">%s</a>', get_permalink(), __('View Listing', 'wp_listings')); /** wrap in div with column class, and output **/ printf('<article id="post-%s" class="listing entry one-third %s"><div class="listing-wrap">%s</div><!-- .listing-wrap --></article><!-- article#post-## -->', get_the_id(), $first, apply_filters('wp_listings_featured_listings_widget_loop', $loop)); if (3 == $count) { // if counter is 3, reset to 0 $count = 0; } } if (function_exists('equity')) { equity_posts_nav(); } elseif (function_exists('genesis_init')) { genesis_posts_nav(); } else { wp_listings_paging_nav(); } }
function wp_listings_shortcode($atts, $content = null) { extract(shortcode_atts(array('id' => '', 'taxonomy' => '', 'term' => '', 'limit' => '', 'columns' => ''), $atts)); /** * if limit is empty set to all */ if (!$limit) { $limit = -1; } /** * if columns is empty set to 0 */ if (!$columns) { $columns = 0; } /* * query args based on parameters */ $query_args = array('post_type' => 'listing', 'posts_per_page' => $limit); if ($id) { $query_args = array('post_type' => 'listing', 'post__in' => explode(',', $id)); } if ($term && $taxonomy) { $query_args = array('post_type' => 'listing', 'posts_per_page' => $limit, 'tax_query' => array(array('taxonomy' => $taxonomy, 'field' => 'slug', 'terms' => $term))); } /* * start loop */ global $post; $listings_array = get_posts($query_args); $count = 0; $output = '<div class="wp-listings-shortcode">'; foreach ($listings_array as $post) { setup_postdata($post); $count = $count == $columns ? 1 : $count + 1; $first_class = 1 == $count ? 'first' : ''; $output .= '<div class="listing-wrap ' . get_column_class($columns) . ' ' . $first_class . '"><div class="listing-widget-thumb"><a href="' . get_permalink() . '" class="listing-image-link">' . get_the_post_thumbnail($post->ID, 'listings') . '</a>'; if ('' != wp_listings_get_status()) { $output .= '<span class="listing-status ' . strtolower(str_replace(' ', '-', wp_listings_get_status())) . '">' . wp_listings_get_status() . '</span>'; } $output .= '<div class="listing-thumb-meta">'; if ('' != get_post_meta($post->ID, '_listing_text', true)) { $output .= '<span class="listing-text">' . get_post_meta($post->ID, '_listing_text', true) . '</span>'; } elseif ('' != wp_listings_get_property_types()) { $output .= '<span class="listing-property-type">' . wp_listings_get_property_types() . '</span>'; } if ('' != get_post_meta($post->ID, '_listing_price', true)) { $output .= '<span class="listing-price">' . get_post_meta($post->ID, '_listing_price', true) . '</span>'; } $output .= '</div><!-- .listing-thumb-meta --></div><!-- .listing-widget-thumb -->'; if ('' != get_post_meta($post->ID, '_listing_open_house', true)) { $output .= '<span class="listing-open-house">' . __("Open House", 'wp_listings') . ': ' . get_post_meta($post->ID, '_listing_open_house', true) . '</span>'; } $output .= '<div class="listing-widget-details"><h3 class="listing-title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h3>'; $output .= '<p class="listing-address"><span class="listing-address">' . wp_listings_get_address() . '</span><br />'; $output .= '<span class="listing-city-state-zip">' . wp_listings_get_city() . ', ' . wp_listings_get_state() . ' ' . get_post_meta($post->ID, '_listing_zip', true) . '</span></p>'; if ('' != get_post_meta($post->ID, '_listing_bedrooms', true) || '' != get_post_meta($post->ID, '_listing_bathrooms', true) || '' != get_post_meta($post->ID, '_listing_sqft', true)) { $output .= '<ul class="listing-beds-baths-sqft"><li class="beds">' . get_post_meta($post->ID, '_listing_bedrooms', true) . '<span>' . __("Beds", 'wp_listings') . '</span></li> <li class="baths">' . get_post_meta($post->ID, '_listing_bathrooms', true) . '<span>' . __("Baths", 'wp_listings') . '</span></li> <li class="sqft">' . get_post_meta($post->ID, '_listing_sqft', true) . '<span>' . __("Square Feet", 'wp_listings') . '</span></li></ul>'; } $output .= '</div><!-- .listing-widget-details --></div><!-- .listing-wrap -->'; } $output .= '</div><!-- .wp-listings-shortcode -->'; wp_reset_postdata(); return $output; }
function widget($args, $instance) { extract($args); $column_class = $instance['use_columns'] ? $this->get_column_class($instance['number_columns']) : ''; echo $before_widget; if (!empty($instance['title'])) { echo $before_title . apply_filters('widget_title', $instance['title'], $instance, $this->id_base) . $after_title; } if (!empty($instance['posts_term'])) { $posts_term = explode(',', $instance['posts_term']); } $query_args = array('post_type' => 'listing', 'posts_per_page' => $instance['posts_per_page'], 'paged' => get_query_var('paged') ? get_query_var('paged') : 1); if (!empty($instance['posts_term']) && count($posts_term) == 2) { $query_args[$posts_term['0']] = $posts_term['1']; } $wp_listings_widget_query = new WP_Query($query_args); $count = 0; global $post; if ($wp_listings_widget_query->have_posts()) { while ($wp_listings_widget_query->have_posts()) { $wp_listings_widget_query->the_post(); $count = $count == $instance['number_columns'] ? 1 : $count + 1; $first_class = 1 == $count && 1 == $instance['use_columns'] ? ' first' : ''; $loop = sprintf('<div class="listing-widget-thumb"><a href="%s" class="listing-image-link">%s</a>', get_permalink(), get_the_post_thumbnail($post->ID, $instance['image_size'])); if ('' != wp_listings_get_status()) { $loop .= sprintf('<span class="listing-status %s">%s</span>', strtolower(str_replace(' ', '-', wp_listings_get_status())), wp_listings_get_status()); } $loop .= sprintf('<div class="listing-thumb-meta">'); if ('' != get_post_meta($post->ID, '_listing_text', true)) { $loop .= sprintf('<span class="listing-text">%s</span>', get_post_meta($post->ID, '_listing_text', true)); } elseif ('' != wp_listings_get_property_types()) { $loop .= sprintf('<span class="listing-property-type">%s</span>', wp_listings_get_property_types()); } if ('' != get_post_meta($post->ID, '_listing_price', true)) { $loop .= sprintf('<span class="listing-price">%s</span>', get_post_meta($post->ID, '_listing_price', true)); } $loop .= sprintf('</div><!-- .listing-thumb-meta --></div><!-- .listing-widget-thumb -->'); if ('' != get_post_meta($post->ID, '_listing_open_house', true)) { $loop .= sprintf('<span class="listing-open-house">Open House: %s</span>', get_post_meta($post->ID, '_listing_open_house', true)); } $loop .= sprintf('<div class="listing-widget-details"><h3 class="listing-title"><a href="%s">%s</a></h3>', get_permalink(), get_the_title()); $loop .= sprintf('<p class="listing-address"><span class="listing-address">%s</span><br />', wp_listings_get_address()); $loop .= sprintf('<span class="listing-city-state-zip">%s, %s %s</span></p>', wp_listings_get_city(), wp_listings_get_state(), get_post_meta($post->ID, '_listing_zip', true)); if ('' != get_post_meta($post->ID, '_listing_bedrooms', true) || '' != get_post_meta($post->ID, '_listing_bathrooms', true) || '' != get_post_meta($post->ID, '_listing_sqft', true)) { $loop .= sprintf('<ul class="listing-beds-baths-sqft"><li class="beds">%s<span>Beds</span></li> <li class="baths">%s<span>Baths</span></li> <li class="sqft">%s<span>Sq ft</span></li></ul>', get_post_meta($post->ID, '_listing_bedrooms', true), get_post_meta($post->ID, '_listing_bathrooms', true), get_post_meta($post->ID, '_listing_sqft', true)); } $loop .= sprintf('</div><!-- .listing-widget-details -->'); $loop .= sprintf('<a href="%s" class="button btn-primary more-link">%s</a>', get_permalink(), __('View Listing', 'wp_listings')); /** wrap in div with possible column class, and output **/ printf('<div class="listing %s post-%s"><div class="listing-wrap">%s</div></div>', $column_class . $first_class, $post->ID, apply_filters('wp_listings_featured_listings_widget_loop', $loop)); } } wp_reset_postdata(); echo $after_widget; }