Understanding and Customizing Property List Templates in WpResidence
Introduction
The property_list.php and property_list_half.php files are key templates in the WpResidence theme, responsible for displaying property listings in different layouts. These files can be found in the root directory of the WpResidence theme.
Template Structure and Functionality
1. property_list.php
This template displays a full-width list of properties. Here’s a breakdown of its main components:
1.1 Template Declaration
At the top of the file, you’ll find:
/**
* Template Name: Properties list
*
* @package WpResidence
*/
This declares the template name, making it selectable in the WordPress page attributes.
1.2 WpResidence Core Plugin Check
The template checks for the WpResidence Core plugin:
if (!function_exists('wpestate_residence_functionality')) {
wp_die(esc_html__('This page requires the WpResidence Core Plugin. Please activate it from the plugins menu!', 'wpresidence'));
}
This ensures that the necessary functionality is available.
1.3 Variable Initialization
The template initializes various variables used throughout the page:
$wpestate_currency = esc_html(wpresidence_get_option('wp_estate_currency_symbol', ''));
$where_currency = esc_html(wpresidence_get_option('wp_estate_where_currency_symbol', ''));
$wpestate_prop_unit = esc_html(wpresidence_get_option('wp_estate_prop_unit',''));
$property_number_to_show = intval(wpresidence_get_option('wp_estate_prop_no', ''));
$curent_fav = wpestate_return_favorite_listings_per_user();
These variables are fetched from theme options and user data. The functions used here can be found in the WpResidence Core plugin, typically in files like estate_functions.php or estate_options.php.
1.4 Query Arguments and Property Selection
The template creates query arguments and selects properties:
$temp_arguments = wpresidence_create_arguments_for_property_list($post->ID);
$arguments_array = wpestate_create_query_arguments($temp_arguments);
$args = $arguments_array['query_arguments'];
$transient_appendix = $arguments_array['transient_appendix'];
These functions (wpresidence_create_arguments_for_property_list and wpestate_create_query_arguments) can be found in the WpResidence Core plugin, typically in a file like estate_property_lists.php.
1.5 Property Selection and Caching
The template attempts to retrieve cached property selections:
$prop_selection = wpestate_request_transient_cache('wpestate_prop_list'.$transient_appendix);
if($prop_selection == false){
if($order == 0){
$prop_selection = wpestate_return_filtered_by_order($args);
} else {
$prop_selection = new WP_Query($args);
}
wpestate_set_transient_cache('wpestate_prop_list'.$transient_appendix, $prop_selection, 60*60*4);
}
This caching mechanism improves performance by storing query results. The caching functions can typically be found in a file like estate_caching.php in the WpResidence Core plugin.
1.6 Template Inclusion
The template includes the core display logic:
include(locate_template('templates/properties_list_templates/property_list_page_normal_map_core.php'));
This file contains the HTML structure for displaying the property list.
2. property_list_half.php
This template is similar to property_list.php but displays properties in a half-map layout. The main differences are:
2.1 Template Declaration
// Template Name: Properties list half
2.2 Template Inclusion
Instead of the normal map core, it includes:
include(locate_template('templates/properties_list_templates/property_list_page_half_map_core.php'));
This file contains the HTML structure for the half-map layout.
Customization and Extension
1. Modifying Property List Order
The property list order can be modified by changing the ‘listing_filter’ post meta. You can add a custom field to your property list page and set its value to change the ordering. The order values are defined in the theme and typically include options like ‘default’, ‘price_high’, ‘price_low’, etc.
2. Changing Property Card Layout
To modify the property card layout, you can create a child theme and override the property card templates. For example, to change the layout of Type 1 property cards:
- Create a folder in your child theme: ‘templates/property_cards_templates/’
- Copy ‘property_unit_type1.php’ from the parent theme to this new folder
- Modify the copied file as needed
CSS Customization
The main CSS classes for property listings can be found in the following SCSS files:
- /sass/_property_lists.scss: Contains styles for overall list layouts
- /sass/_property_unit.scss: Contains styles for individual property units
- /sass/_property_units_type1.scss (and similar files for other types): Contains specific styles for each property card type
To customize these styles, it’s recommended to use a child theme and create a custom CSS file that overrides the necessary styles.