Skip to content

Instantly share code, notes, and snippets.

/archive-listing.php

Created Jan 27, 2015
Embed
What would you like to do?
<?php
/**
* This file adds the Archive Listings Template to the AgentPress Pro Theme.
*
* @author StudioPress
* @package AgentPress Pro
* @subpackage Customizations
*/
//* Force full width layout
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
//* Add listings archive widget area
add_action( 'genesis_before_content_sidebar_wrap', 'agentpress_archive_widget' );
function agentpress_archive_widget() {
if ( is_active_sidebar( 'listings-archive' ) ) {
genesis_widget_area( 'listings-archive', array(
'before' => '<div class="listing-archive full-width widget-area">',
'after' => '</div>',
) );
}
}
//* Relocate archive intro text
remove_action( 'genesis_before_loop', 'genesis_do_taxonomy_title_description', 15 );
add_action( 'genesis_before_content_sidebar_wrap', 'genesis_do_taxonomy_title_description' );
//* Remove the standard loop
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'agentpress_listing_archive_loop' );
/**
* Custom loop for listing archive page
*/
function agentpress_listing_archive_loop() {
if ( have_posts() ) : while ( have_posts() ) : the_post();
$listing_price = genesis_get_custom_field( '_listing_price' );
$listing_text = genesis_get_custom_field( '_listing_text' );
$address = genesis_get_custom_field( '_listing_address' );
$city = genesis_get_custom_field( '_listing_city' );
$state = genesis_get_custom_field( '_listing_state' );
$zip = genesis_get_custom_field( '_listing_zip' );
$loop = ''; // init
$loop .= sprintf( '<a href="%s">%s</a>', get_permalink(), genesis_get_image( array( 'size' => 'properties' ) ) );
if ( $listing_price ) {
$loop .= sprintf( '<span class="listing-price">%s</span>', $listing_price );
}
if ( $listing_text ) {
$loop .= sprintf( '<span class="listing-text">%s</span>', $listing_text );
}
if ( $address ) {
$loop .= sprintf( '<span class="listing-address">%s</span>', $address );
}
if ( $city || $state || $zip ) {
//* count number of completed fields
$pass = count( array_filter( array( $city, $state, $zip ) ) );
//* If only 1 field filled out, no comma
if ( 1 == $pass ) {
$city_state_zip = $city . $state . $zip;
} //* If city filled out, comma after city
elseif ( $city ) {
$city_state_zip = $city . ", " . $state . " " . $zip;
} //* Otherwise, comma after state
else {
$city_state_zip = $city . " " . $state . ", " . $zip;
}
$loop .= sprintf( '<span class="listing-city-state-zip">%s</span>', trim( $city_state_zip ) );
}
$loop .= sprintf( '<a href="%s" class="more-link">%s</a>', get_permalink(), __( 'View Listing', 'agentpress' ) );
/** wrap in post class div, and output **/
printf( '<div class="%s"><div class="widget-wrap"><div class="listing-wrap">%s</div></div></div>', join( ' ', get_post_class() ), $loop );
endwhile;
genesis_posts_nav();
else: printf( '<div class="entry"><p>%s</p></div>', __( 'Sorry, no properties matched your criteria.', 'agentpress' ) );
endif;
}
function cg_google_maps_scripts() {
// Custom css file to handle google maps display
wp_enqueue_style( 'gmaps', get_stylesheet_directory_uri() . '/css/acfmap.css' );
// Custom script to handle rendering map, placement of markers, and html info windows
wp_enqueue_script( 'gmaps', get_stylesheet_directory_uri() . '/js/acfmap.js', array( 'gmapsapi' ), '1.0.0', true );
// Google Maps API is dependency for gmaps script called above
// Gmaps must be called AFTER the API, so we run the API as the dependency enqueued after gmaps
// format to call Google Maps API
// But with our correct API Key (for OrgSpring Use Only)
wp_enqueue_script( 'gmapsapi', 'https://maps.googleapis.com/maps/api/js?key=AIzaSyAZ77J9xyxSN2aWlpN-KKZagNgy6VZEQuQ', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'cg_google_maps_scripts' );
/**
* Google Maps using ACF Pro
* Add the required classes required by Google Maps API, including lat/lng coordinates, markers, and
* html for info windows on marker when clicked
*
* @since 1.0.0
* @author Craig Grella
* @link http://orgspring.com
*
*/
// Add custom loop to populate object with posts and location meta from ACF fields
add_action( 'genesis_after_header', 'os_do_loop' );
function os_do_loop() {
// Create the section that will hold the google map
// The name used here for the class is repeated in JS and CSS files
echo '<div class="google-acfmap">';
if ( have_posts() ) : while ( have_posts() ) : the_post();
// Get location coordinates from google maps field in ACF
$location = get_field( 'google_maps' );
// Set required Google Maps Marker info with lat/lng
// Use post link and title for HTML info window on marker on map
// Show address on HTML info window also
?>
<div class="marker" data-lat="<?php echo $location[ lat ]; ?>" data-lng="<?php echo $location[ lng ]; ?>"
data-icon="<?php genesis_image( array( 'format' => 'url', 'size' => 'mapthumb' ) ); ?>">
<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
<div class="location-image"><?php genesis_image(); ?></div>
<p><?php echo $location['address']; ?></p>
</div>
<?
endwhile;
echo '</div><!-- .google-acfmap -->';
endif;
}
genesis();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.