Advertisement
Guest User

archive-property.php

a guest
Apr 13th, 2020
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.12 KB | None | 0 0
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3.     exit; // Exit if accessed directly
  4. }
  5. get_header('ere');
  6. /**
  7.  * ere_before_main_content hook.
  8.  *
  9.  * @hooked ere_output_content_wrapper_start - 10 (outputs opening divs for the content)
  10.  */
  11. do_action( 'ere_before_main_content' );
  12. ?>
  13. <?php
  14. global $post, $taxonomy_title, $taxonomy_name;
  15.  
  16. $custom_property_layout_style = ere_get_option('archive_property_layout_style', 'property-grid');
  17.  
  18. $custom_property_items_amount = ere_get_option('archive_property_items_amount', '6');
  19. $custom_property_image_size = ere_get_option( 'archive_property_image_size', '330x180' );
  20. $custom_property_columns = ere_get_option('archive_property_columns', '3');
  21. $custom_property_columns_gap = ere_get_option('archive_property_columns_gap', 'col-gap-30');
  22. $custom_property_items_md = ere_get_option('archive_property_items_md', '3');
  23. $custom_property_items_sm = ere_get_option('archive_property_items_sm', '2');
  24. $custom_property_items_xs = ere_get_option('archive_property_items_xs', '1');
  25. $custom_property_items_mb = ere_get_option('archive_property_items_mb', '1');
  26.  
  27. $property_item_class = array();
  28.  
  29. if (isset($_SESSION["property_view_as"]) && !empty($_SESSION["property_view_as"]) && in_array($_SESSION["property_view_as"], array('property-list', 'property-grid'))) {
  30.     $custom_property_layout_style = $_SESSION["property_view_as"];
  31. }
  32.  
  33. $wrapper_classes = array(
  34.     'ere-property clearfix',
  35.     $custom_property_layout_style,
  36.     $custom_property_columns_gap
  37. );
  38.  
  39. if ($custom_property_layout_style == 'property-list') {
  40.     $wrapper_classes[] = 'list-1-column';
  41. }
  42.  
  43. if ($custom_property_columns_gap == 'col-gap-30') {
  44.     $property_item_class[] = 'mg-bottom-30';
  45. } elseif ($custom_property_columns_gap == 'col-gap-20') {
  46.     $property_item_class[] = 'mg-bottom-20';
  47. } elseif ($custom_property_columns_gap == 'col-gap-10') {
  48.     $property_item_class[] = 'mg-bottom-10';
  49. }
  50.  
  51. $wrapper_classes[] = 'columns-' . $custom_property_columns;
  52. $wrapper_classes[] = 'columns-md-' . $custom_property_items_md;
  53. $wrapper_classes[] = 'columns-sm-' . $custom_property_items_sm;
  54. $wrapper_classes[] = 'columns-xs-' . $custom_property_items_xs;
  55. $wrapper_classes[] = 'columns-mb-' . $custom_property_items_mb;
  56. $property_item_class[] = 'ere-item-wrap';
  57. $args = array(
  58.     'posts_per_page' => $custom_property_items_amount,
  59.     'post_type' => 'property',
  60.     'orderby'   => array(
  61.         'menu_order'=>'ASC',
  62.         'date' =>'DESC',
  63.     ),
  64.     'offset' => (max(1, get_query_var('paged')) - 1) * $custom_property_items_amount,
  65.     'ignore_sticky_posts' => 1,
  66.     'post_status' => 'publish'
  67. );
  68. if (isset($_GET['sortby']) && in_array($_GET['sortby'], array('a_price', 'd_price', 'a_date', 'd_date', 'featured', 'most_viewed'))) {
  69.     if ($_GET['sortby'] == 'a_price') {
  70.         $args['orderby'] = 'meta_value_num';
  71.         $args['meta_key'] = ERE_METABOX_PREFIX . 'property_price';
  72.         $args['order'] = 'ASC';
  73.     } else if ($_GET['sortby'] == 'd_price') {
  74.         $args['orderby'] = 'meta_value_num';
  75.         $args['meta_key'] = ERE_METABOX_PREFIX . 'property_price';
  76.         $args['order'] = 'DESC';
  77.     } else if ($_GET['sortby'] == 'featured') {
  78.         $args['orderby'] = array(
  79.             'meta_value_num' => 'DESC',
  80.             'date' => 'DESC',
  81.         );
  82.         $args['meta_key'] = ERE_METABOX_PREFIX . 'property_featured';
  83.     }
  84.     else if ($_GET['sortby'] == 'most_viewed') {
  85.         $args['orderby'] = 'meta_value_num';
  86.         $args['meta_key'] = ERE_METABOX_PREFIX . 'property_views_count';
  87.         $args['order'] = 'DESC';
  88.     }
  89.     else if ($_GET['sortby'] == 'a_date') {
  90.         $args['orderby'] = 'date';
  91.         $args['order'] = 'ASC';
  92.     } else if ($_GET['sortby'] == 'd_date') {
  93.         $args['orderby'] = 'date';
  94.         $args['order'] = 'DESC';
  95.     }
  96. }
  97. else{
  98.     $featured_toplist = ere_get_option('featured_toplist', 1);
  99.     if($featured_toplist!=0)
  100.     {
  101.         $args['orderby'] = array(
  102.             'menu_order'=>'ASC',
  103.             'meta_value_num' => 'DESC',
  104.             'date' => 'DESC',
  105.         );
  106.         $args['meta_key'] = ERE_METABOX_PREFIX . 'property_featured';
  107.     }
  108. }
  109. $property_status=ere_get_property_status_search();
  110. $property_status_arr = array();
  111. if ($property_status) {
  112.     foreach ($property_status as $property_stt) {
  113.         $property_status_arr[] = $property_stt->slug;
  114.     }
  115. }
  116. $tax_query = array();
  117. if (isset($_GET['status']) && in_array($_GET['status'], $property_status_arr) && $taxonomy_name != 'property-status') {
  118.     $tax_query[] = array(
  119.         'taxonomy' => 'property-status',
  120.         'field' => 'slug',
  121.         'terms' => explode(',', ere_clean(wp_unslash($_GET['status']))),
  122.         'operator' => 'IN'
  123.     );
  124. }
  125. if (is_tax()) {
  126.     $current_term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
  127.     $taxonomy_title = $current_term->name;
  128.     $taxonomy_name = get_query_var('taxonomy');
  129.     if (!empty($taxonomy_name)) {
  130.         $tax_query[] = array(
  131.             'taxonomy' => $taxonomy_name,
  132.             'field' => 'slug',
  133.             'terms' => $current_term->slug
  134.         );
  135.     }
  136. }
  137.  
  138. $tax_count = count($tax_query);
  139. if ($tax_count > 0) {
  140.     $args['tax_query'] = array(
  141.         'relation' => 'AND',
  142.         $tax_query
  143.     );
  144. }
  145. $author_id = $agent_id = '';
  146. if (isset($_GET['user_id']) ||isset($_GET['agent_id']) ) {
  147.     if (isset($_GET['user_id'])) {
  148.         $author_id = ere_clean(wp_unslash($_GET['user_id']));
  149.         $agent_id = get_the_author_meta(ERE_METABOX_PREFIX . 'author_agent_id', $author_id);
  150.     }
  151.     if (isset($_GET['agent_id'])) {
  152.         $agent_id = ere_clean(wp_unslash($_GET['agent_id']));
  153.         $author_id = get_post_meta($agent_id, ERE_METABOX_PREFIX . 'agent_user_id', true);
  154.     }
  155.     if (!empty($author_id) && $author_id > 0 && !empty($agent_id) && $agent_id > 0) {
  156.         $args['meta_query'] = array(
  157.             'relation' => 'OR',
  158.             array(
  159.                 'key' => ERE_METABOX_PREFIX . 'property_agent',
  160.                 'value' => $agent_id,
  161.                 'compare' => '='
  162.             ),
  163.             array(
  164.                 'key' => ERE_METABOX_PREFIX . 'property_author',
  165.                 'value' => $author_id,
  166.                 'compare' => '='
  167.             )
  168.         );
  169.     } else {
  170.         if (!empty($author_id) && $author_id > 0) {
  171.             $args['author'] = $author_id;
  172.         } else if (!empty($agent_id) && $agent_id > 0) {
  173.             $args['meta_query'] = array(
  174.                 array(
  175.                     'key' => ERE_METABOX_PREFIX . 'property_agent',
  176.                     'value' => $agent_id,
  177.                     'compare' => '='
  178.                 )
  179.             );
  180.         }
  181.     }
  182. }
  183. $data = new WP_Query($args);
  184. $total_post = $data->found_posts;
  185.  
  186. $min_suffix = ere_get_option('enable_min_css', 0) == 1 ? '.min' : '';
  187. wp_print_styles( ERE_PLUGIN_PREFIX . 'property');
  188. wp_print_styles( ERE_PLUGIN_PREFIX . 'archive-property');
  189.  
  190. $min_suffix_js = ere_get_option('enable_min_js', 0) == 1 ? '.min' : '';
  191. wp_enqueue_script(ERE_PLUGIN_PREFIX . 'archive-property', ERE_PLUGIN_URL . 'public/assets/js/property/ere-archive-property' . $min_suffix_js . '.js', array('jquery'), ERE_PLUGIN_VER, true);
  192. ?>
  193.     <div class="ere-archive-property-wrap ere-property-wrap">
  194.         <?php do_action('ere_archive_property_before_main_content'); ?>
  195.         <div class="ere-archive-property archive-property">
  196.             <div class="above-archive-property">
  197.                 <?php do_action('ere_archive_property_heading', $total_post, $taxonomy_title, $agent_id, $author_id); ?>
  198.                 <?php do_action('ere_archive_property_action', $taxonomy_name); ?>
  199.             </div>
  200.             <div class="<?php echo join(' ', $wrapper_classes) ?>">
  201.                 <?php if ($data->have_posts()) :
  202.                     while ($data->have_posts()): $data->the_post(); ?>
  203.                         <?php ere_get_template('content-property.php', array(
  204.                             'property_item_class' => $property_item_class,
  205.                             'custom_property_image_size' => $custom_property_image_size
  206.                         )); ?>
  207.  
  208.  
  209.                     <?php endwhile;
  210.                 else: ?>
  211.                     <div class="item-not-found"><?php esc_html_e('No item found', 'essential-real-estate'); ?></div>
  212.                 <?php endif; ?>
  213.                 <div class="clearfix"></div>
  214.                 <?php
  215.                 $max_num_pages = $data->max_num_pages;
  216.                 ere_get_template('global/pagination.php', array('max_num_pages' => $max_num_pages));
  217.                 wp_reset_postdata(); ?>
  218.             </div>
  219.         </div>
  220.         <?php do_action('ere_archive_property_after_main_content'); ?>
  221.     </div>
  222. <?php
  223. /**
  224.  * ere_after_main_content hook.
  225.  *
  226.  * @hooked ere_output_content_wrapper_end - 10 (outputs closing divs for the content)
  227.  */
  228. do_action( 'ere_after_main_content' );
  229. /**
  230.  * ere_sidebar_property hook.
  231.  *
  232.  * @hooked ere_sidebar_property - 10
  233.  */
  234.  
  235. // The code bellow is the only file modified here, to get rid of the sidebar that is positioned below the arvhive property page, domain.com/property.
  236.  
  237. //do_action('ere_sidebar_property');
  238. get_footer('ere');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement