<?php /* Template Name: RentPress Neighborhood Archive */

add_action('wp_enqueue_scripts', 'rentpress_term_style');
function rentpress_term_style()
{
  wp_enqueue_style('city-archive', RENTPRESS_PLUGIN_PUBLIC_TEMPLATES_DIR . 'template-city-archive-styles.css');
}
get_header();

$options = get_option('rentpress_options');
$city_image = $options['rentpress_default_city_image_section'];
$accentColor = $options['rentpress_accent_color_section_input'];
$hoodImage = !is_null(get_the_post_thumbnail()) ? get_the_post_thumbnail_url($post_id, "full") : $city_image;
$content = apply_filters('the_content', get_post_field('post_content', $post->ID));

$args = array(
  'post_type'		=> 'rentpress_hood',
  'post_status' => 'publish',
  'meta_key' => 'rentpress_custom_field_neighborhood_property_codes',
  'meta_value' => ' ',
  'meta_compare' => '!=',
  'orderby' 		=> 'title',
  'order' 		=> 'ASC',
  'nopaging' => true
);
$hoods = get_posts($args);

?>
<div class="rentpress-page-hero">
    <header class="rentpress-page-hero-full">
        <h1 class="rentpress-inherited-font-family rentpress-page-title rentpress-neighborhood-title">
            <?php echo 'Explore <br />'. esc_html(get_the_title()); ?></h1>
        <img src="<?php echo esc_url($hoodImage); ?>"
            class="lazyload rentpress-neighborhood-archive-banner rentpress-template-banner"
            alt="<?php echo esc_attr(get_the_title());?> banner">
        >
    </header>
</div>

<main id="main" class="clearfix main-content" role="main">
    <?php if ($content) : ?>
    <section class="entry-content">
        <?php echo wp_kses_post($content); ?>
    </section>
    <?php endif ; ?>

    <section class="city-term-grid neighborhood-grid">
        <?php foreach ($hoods as $hood) :
			$image = !empty(get_the_post_thumbnail($hood->ID)) ? get_the_post_thumbnail_url($hood->ID, "large") : $city_image;
    ?>

        <div class="is-rp-city is-rp-neighborhood flex-grid-thirds">
            <a href="<?php echo esc_url(get_permalink($hood->ID)); ?>">
                <figure class="rp-city-figure rp-neighborhood-figure">
                    <img class="rp-city-image rp-neighborhood-image" src="<?php echo esc_url($image); ?>" alt="
            <?php echo esc_html(get_the_title($hood->ID)); ?>">
                </figure>
                <section class="rp-city-details rp-neighborhood-details">
                    <div class="rp-city-top rp-neighborhood-top">
                        <h2 class="rp-city-name rp-city-name rp-neighborhood-name"
                            style="font-weight: bold; color: <?php echo esc_attr($accentColor); ?> ;">
                            <?php echo esc_attr(get_the_title($hood->ID)); ?></h2>
                    </div>
                </section>
            </a>
        </div>

        <?php endforeach ; ?>
    </section>
</main><!-- #main -->
<?php get_footer(); ?>