0

I am using Awesome Weather Widget for displaying weather information on my site. However, my website is real estate portal running the Houzez theme, and what I want is that on every property page I am showing about city tab in which I want to display the information of weather widget. For that to work automatically i want to get city taxonomy automatically inside that code, so that user is viewing a property from which is in london, then it display london's weather info, and if user is viewing property of new york then it should display that location's weather info. For this I have created a display template in which i am showing city info which i have described at backend then i am showing property count in that city and then i am displaying weather info. so how can i get city term so, that it will do the work. here is the full code:

<?php
/**
 * Created by Krieta Homes. New template to display city info.
 * User: Vinay
 * Date: 21/01/16
 * Time: 7:17 PM
 */
global $post_meta_data;
$city = houzez_taxonomy_simple('property_city');
$city_url = "http://krieta.com/city/".$city;
$google_map_address = get_post_meta( get_the_ID(), 'fave_property_map_address', true );
$google_map_address_url = "http://maps.google.com/?q=".$google_map_address;
if( !empty($city) ) {

?>
<div id="city" class="detail-city detail-block target-block">
<div class="detail-title">

    <h2 class="title-left"><?php esc_html_e( 'About', 'houzez' ); ?> <strong> <a target="_blank" href="<?php echo esc_url($city_url); ?>"><?php esc_html_e($city ); ?></a></strong> <?php esc_html_e( 'City', 'houzez' ); ?></h2>
    <?php if( !empty($google_map_address) ) { ?>
    <div class="title-right">
        <a target="_blank" href="<?php echo esc_url($google_map_address_url); ?>"><?php esc_html_e( 'Open on Google Maps', 'houzez' ); ?> <i class="fa fa-map-marker"></i></a>
    </div>
    <?php } ?>
</div>
        <div>
            <?php
            $terms = get_the_terms( $post->ID , 'property_city' ); 
                foreach ( $terms as $term ) {

                $term_link = get_term_link( $term, 'property_city' );
                $name = $term->name;
                if( is_wp_error( $term_link ) )
                 continue;
                echo term_description( $term, 'property_city' );
                } 

            ?>
        </div>
        <div>

            <ul class="list-four-col">
                <?php
                    if( !empty( $city ) ) {
                        echo '<strong>'.esc_html__('Property in', 'houzez').' '.esc_attr( $city ).'&nbsp:</strong>';
                    }
                    if( !empty( $city ) ) {
                        echo '<li><a href="' . esc_url( $term_link ) . '">' .esc_html__($term->count).' '.esc_html__('Properties Listed', 'houzez'). '</a></li>';
                    }
                ?>
            </ul>
        </div>
        <div><?php echo do_shortcode( '[awesome-weather location=".esc_attr( $city ), IN"  forecast_days="5" hide_attribution="1" show_icons="1" text_color="#fff" use_user_location="0" background="http://images.all-free-download.com/images/graphicthumb/crystal_water_drops_with_blurred_background_art_545094.jpg" units="C" locale="en"]' ); ?></div>
<?php } ?>
</div>
  • why is it not showing full post ? – Krieta Homes Aug 2 '17 at 22:35
  • Hi, its not showing, its not giving correct city name, you can see this here at about city section, krieta.com/property/2-bhk-flat-rent-boring-road – Krieta Homes Aug 4 '17 at 6:24
  • I dont know php that much, please help. city shows wrong while at title its showing correct city – Krieta Homes Aug 4 '17 at 6:39
  • <div><?php echo do_shortcode( '[awesome-weather location=".esc_attr( $city ), IN" forecast_days="5" hide_attribution="1" show_icons="1" text_color="#fff" use_user_location="0" background="images.all-free-download.com/images/graphicthumb/…" units="C" locale="en"]' ); ?></div> – Krieta Homes Aug 4 '17 at 6:39
  • if i add manualy Patna, IN then its shows the right info but I want to output it automaticaly. – Krieta Homes Aug 4 '17 at 6:40
0
global $post_meta_data;
$city = houzez_taxonomy_simple('property_city');
$city_url = "http://krieta.com/city/".$city;
$google_map_address = get_post_meta( get_the_ID(), 'fave_property_map_address', true );
$google_map_address_url = "http://maps.google.com/?q=".$google_map_address;
if( !empty($city) ) {

?>
<div id="city" class="detail-city detail-block target-block">
<div class="detail-title">

    <h2 class="title-left"><?php esc_html_e( 'About', 'houzez' ); ?> <strong> <a target="_blank" href="<?php echo esc_url($city_url); ?>"><?php esc_html_e($city ); ?></a></strong> <?php esc_html_e( 'City', 'houzez' ); ?></h2>
    <?php if( !empty($google_map_address) ) { ?>
    <div class="title-right">
        <a target="_blank" href="<?php echo esc_url($google_map_address_url); ?>"><?php esc_html_e( 'Open on Google Maps', 'houzez' ); ?> <i class="fa fa-map-marker"></i></a>
    </div>
    <?php } ?>
</div>
        <div>
            <?php
            $terms = get_the_terms( $post->ID , 'property_city' ); 
                foreach ( $terms as $term ) {

                $term_link = get_term_link( $term, 'property_city' );
                $name = $term->name;
                if( is_wp_error( $term_link ) )
                 continue;
                echo term_description( $term, 'property_city' );
                } 

            ?>
        </div>
        <div>

            <ul class="list-four-col">
                <?php
                    if( !empty( $city ) ) {
                        echo '<strong>'.esc_html__('Property in', 'houzez').' '.esc_attr( $city ).'&nbsp:</strong>';
                    }
                    if( !empty( $city ) ) {
                        echo '<li><a href="' . esc_url( $term_link ) . '">' .esc_html__($term->count).' '.esc_html__('Properties Listed', 'houzez'). '</a></li>';
                    }
                ?>
            </ul>
        </div>
        <div><?php echo do_shortcode( '[awesome-weather location=".esc_attr( $city ), IN"  forecast_days="5" hide_attribution="1" show_icons="1" text_color="#fff" use_user_location="0" background="http://images.all-free-download.com/images/graphicthumb/crystal_water_drops_with_blurred_background_art_545094.jpg" units="C" locale="en"]' ); ?></div>
<?php } ?>
</div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.