Last active
May 17, 2020 23:34
-
-
Save srikat/e36e922542086a60d698 to your computer and use it in GitHub Desktop.
Page Templates for displaying 'For Sale' and 'For Rent' Listings in AgentPress Pro. http://sridharkatakam.com/page-templates-displaying-sale-rent-listings-agentpress-pro/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file displays Listings that are available for Rent. | |
* | |
*/ | |
add_filter( 'body_class', 'sk_body_class' ); | |
/** | |
* Adds a css class to the body element | |
* | |
* @param array $classes the current body classes | |
* @return array $classes modified classes | |
*/ | |
function sk_body_class( $classes ) { | |
$classes[] = 'property-type'; | |
return $classes; | |
} | |
//* 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>', | |
) ); | |
} | |
} | |
function sk_page_intro() { | |
$content = get_post( get_option( 'page_for_posts' ) )->post_content; | |
if( $content ) { | |
echo '<div class="page-intro">' . wpautop( $content ) . '</div>'; | |
} | |
} | |
add_action( 'genesis_before_content', 'sk_page_intro' ); | |
//* Remove the standard loop | |
remove_action( 'genesis_loop', 'genesis_do_loop' ); | |
add_action( 'genesis_loop', 'sk_listing_for_rent_loop' ); | |
/** | |
* Custom loop for listing page | |
*/ | |
function sk_listing_for_rent_loop() { | |
global $paged; | |
// accepts any wp_query args | |
$args = (array( | |
'post_type' => 'listing', | |
'paged' => $paged, | |
'posts_per_page' => 10, | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'types', | |
'field' => 'slug', | |
'terms' => 'for-rent', | |
), | |
), | |
)); | |
// The Query | |
$the_query = new WP_Query( $args ); | |
// genesis_custom_loop( $args ); | |
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->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; | |
} | |
genesis(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file displays Listings that are available for Sale. | |
* | |
*/ | |
add_filter( 'body_class', 'sk_body_class' ); | |
/** | |
* Adds a css class to the body element | |
* | |
* @param array $classes the current body classes | |
* @return array $classes modified classes | |
*/ | |
function sk_body_class( $classes ) { | |
$classes[] = 'property-type'; | |
return $classes; | |
} | |
//* 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>', | |
) ); | |
} | |
} | |
function sk_page_intro() { | |
$content = get_post( get_option( 'page_for_posts' ) )->post_content; | |
if( $content ) { | |
echo '<div class="page-intro">' . wpautop( $content ) . '</div>'; | |
} | |
} | |
add_action( 'genesis_before_content', 'sk_page_intro' ); | |
//* Remove the standard loop | |
remove_action( 'genesis_loop', 'genesis_do_loop' ); | |
add_action( 'genesis_loop', 'sk_listing_for_sale_loop' ); | |
/** | |
* Custom loop for listing page | |
*/ | |
function sk_listing_for_sale_loop() { | |
global $paged; | |
// accepts any wp_query args | |
$args = (array( | |
'post_type' => 'listing', | |
'paged' => $paged, | |
'posts_per_page' => 10, | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'types', | |
'field' => 'slug', | |
'terms' => 'for-sale', | |
), | |
), | |
)); | |
// The Query | |
$the_query = new WP_Query( $args ); | |
// genesis_custom_loop( $args ); | |
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->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; | |
} | |
genesis(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* For Sale and For Rent Pages | |
--------------------------------------------- */ | |
.property-type .type-listing { | |
background-color: #fff; | |
color: #1a212b; | |
float: left; | |
margin: 0 0 1.5% 1.5%; | |
overflow: hidden; | |
padding: 0 0 40px; | |
position: relative; | |
text-align: center; | |
width: 32.333333333%; | |
} | |
.property-type .type-listing:nth-of-type(3n+1) { | |
clear: both; | |
margin-left: 0; | |
} | |
@media only screen and (max-width: 768px) { | |
.property-type .type-listing { | |
margin: 0 0 1.5% 1.5%; | |
width: 49.25%; | |
} | |
} | |
@media only screen and (max-width: 480px) { | |
.property-type .type-listing { | |
margin: 0 0 6px; | |
width: 100%; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good evening
can you show us an example page
thank you.