0

add_shortcode( 'collection_view', 'dtwd_special_collection_view' );
function dtwd_special_collection_view( $atts ) {
    $atts = shortcode_atts(
       array(
        'post_type' => 'home-collection',
        'posts_per_page' => '-1',
        'post_status' => 'publish',
        //'meta_key'          => 'price_ranges_for_search',
        //'filter' =>'',
        //'curr-id' => '',
        'curr-hb-id' => '', 
         'pid' => '', 
         'bid' => '', 
        //'orderby'          => 'title',
        'order'                => 'DESC'
       ),
       $atts,
       'show_post'
      );
    ob_start();
    $squery = array(
        'post_type'      => $atts['post_type'],
        'posts_per_page' => -1,
    );
    if($atts['bid']!=''){
        $squery['meta_query'] = array(
            array(
                'key'     => 'builder_name', // ACF field name for the relationship
                'value'   => $atts['bid'],
                'compare' => '=',
            ),
        );
    }
    if($atts['pid']!=''){
  $squery['p'] = $atts['pid'];
 }
    //var_dump($squery);
    $query = new WP_Query( $squery );
    if ( $query->have_posts() ) { ?>
        <div class="post-collection <?php echo $atts['pid'];?>">
        <?php while ( $query->have_posts() ) : $query->the_post(); 
                 @$featured_mimg_url = get_field('collection_photo', get_the_ID());
        $home_build = get_field('home_builder', get_the_ID());
        $home_builder_name = get_the_title(get_field('builder_name', get_the_ID()));
        //$collection_name =  get_field('collection_name', get_the_ID());?>
        <div class="et_pb_row et_pb_gutters2 collection-inner-row <?php echo get_the_ID().'_id_bid_'.get_field('builder_name', get_the_ID());?>" style="width: 100%; max-width: 100%;">
        <div class="et_pb_column et_pb_column_1_2">
            <img class="feat-img" src="<?php echo $featured_mimg_url ?>" alt="<?php the_title(); ?>" />
        </div>
        <div class="et_pb_column et_pb_column_1_2 et-last-child" style="text-align: center;">
            <h2><?php echo $home_builder_name; ?></h2>
            <h3><?php echo get_the_title(get_the_ID()); ?></h3>
                         <div class="et_pb_row cpt-row"  style="width: 100%; max-width: 100%; display: flex;">
            <div class="et_pb_column et_pb_column_1_3">
                <?php if (get_field('price_to_display')) { ?>
                    <div class="img-col" style="padding-bottom: 5px;"><img decoding="async" src="/wp-content/uploads/2023/11/price_icon_2.svg" alt="Price" style="width: 40px; height: auto;" /></div>
                    <div class="price-text"><?php the_field('price_to_display'); ?></div>
                <?php } ?>
            </div>
            <div class="et_pb_column et_pb_column_1_3">
                <?php if (get_field('home_size_to_display')) { ?>
                    <div class="img-col" style="padding-bottom: 5px;"><img decoding="async" src="/wp-content/uploads/2023/11/sqft_icon_2.svg" alt="Price" style="width: 40px; height: auto;" /></div>
                    <div class="price-text"><?php the_field('home_size_to_display'); ?></div>
                <?php } ?>
            </div>
            <div class="et_pb_column et_pb_column_1_3">
                <?php if (get_field('home_style')) { ?>
                    <div class="img-col" style="padding-bottom: 5px;"><img decoding="async" src="/wp-content/uploads/2023/11/floorplan_icon_2.svg" alt="Price" style="width: 40px; height: auto;" /></div>
                    <div class="price-text"><?php the_field('home_style'); ?></div>
                <?php } ?>
            </div>
            </div>
            <p style="line-height: 1.4em;"><?php the_field('collection_summary'); ?></p>
            <?php
            if( have_rows('collection_cta_buttons') ):
            ?>
            <ul class="btn-ul">
            <?php
            while ( have_rows('collection_cta_buttons') ) : the_row();
            ?>
            <li>
            <?php 
            if (get_sub_field('button_text')) { ?>
                <a href="<?php echo get_sub_field('button_link'); ?>" <?php  if(get_sub_field('target')=='1'){ ?> target="_blank" <?php } ?> class="extra-btn <?php  if(get_sub_field('popups_yes')=='1'){ ?> info-popup <?php } ?>"><?php echo get_sub_field('button_text'); ?></a>
            <?php } ?>
            </li>
            <?php
            endwhile;
            ?>
            </ul>
            <?php
            endif;
            ?>
        </div>
        <div class="location_contact">
                <?php 
                    $sales_address = get_field('sales_location_address');
                    $google_maps_link = get_field('google_maps_link');
                                     ?>
                <?php if( have_rows('sales_contact') ):?>
                        <h3>Sales Contact</h3>
                        <ul class="no-list">
                            <?php while( have_rows('sales_contact') ): the_row();?>
                            <li><div class="et_pb_row cpt-row" style="max-width: 100%; width: 100%;"><div class="et_pb_column et_pb_column_1_3 text-right"><p><?php the_sub_field('sales_contact_name'); ?></p></div>
                                <div class="et_pb_column et_pb_column_1_3"><p><a href="tel:<?php the_sub_field('sales_contact_phone_number'); ?>"><i class="fa fa-phone" aria-hidden="true" style="vertical-align: middle;"></i> <?php the_sub_field('sales_contact_phone_number'); ?></a></p></div>
                                <div class="et_pb_column et_pb_column_1_3 text-left"><?php if( have_rows('sales_contact_email_address') ): while( have_rows('sales_contact_email_address') ): the_row();
                                    $email = get_sub_field('add_email_address');
if($email){
    echo $emaillink = '<p style="margin: 0;padding-bottom: 5px;" class="email-buldr"><a href="mailto:'.$email.'" target="_blank" style="color: #4a6916;"> <i class="fa fa-envelope" aria-hidden="true" style="vertical-align: middle;"></i> Email Builder</a></p>';
}
                                 endwhile; endif; 
                                    ?></div></div>
                            </li>
                            <?php endwhile; ?>
                        </ul>
                        <?php if($sales_address!=''){?>
                            <h3>Sales Location</h3>
                            <p><?php echo $sales_address;?></p>
                        <?php }?>
                        <?php endif;  if($google_maps_link!=''){?>
                         <p>&nbsp;</p>
                         <p style="text-align: center;"><a style="color: #D52E2E!important;" href="<?php echo $google_maps_link;?>" target="_blank" class="btn-map">Get Directions</a></p>
                        <?php }?>
        </div>
    </div>
             <div class="collection-divider"></div>
        <?php
                 endwhile;
                  wp_reset_query();
                wp_reset_postdata(); ?>
 <script>
jQuery(document).on('click', '.info-popup', function() {
            get_infos = jQuery(this).parents('.collection-inner-row').find('.location_contact').html();
            jQuery('#location_info').html(get_infos);
        }); 
 </script>
        </div>
<?php $collection = ob_get_clean();
    return $collection;
    }
}

Jagdish Sarma Asked question January 18, 2024
Add a Comment