如何在DO短码php标记中显示分类名称

时间:2017-08-02 作者:Krieta Homes

我正在使用很棒的天气小部件在我的网站上显示天气信息。然而,我的网站是运行Houzez主题的房地产门户网站,我想要的是,在我显示的每个属性页上,都有关于城市的选项卡,我想在其中显示天气小部件的信息。为了自动工作,我想在代码中自动获取城市分类,以便用户查看位于伦敦的某个属性,然后显示伦敦的天气信息,如果用户查看纽约的属性,则应显示该位置的天气信息。为此,我创建了一个显示模板,其中显示我在后端描述的城市信息,然后显示该城市的物业数量,然后显示天气信息。那么,我怎样才能得到城市术语,这样它就能完成工作。以下是完整代码:

<?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>

1 个回复
SO网友:Krieta Homes
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>
结束

相关推荐

customize taxonomy Page

有没有一种解决方案可以自定义分类法页面并使其类似于带有标题h1和自定义侧栏的类别页面?这是我的分类代码:register_taxonomy(\'director\', \'post\', array( \'hierarchical\' => false, \'label\' => \'Realisateur\', \'query_var\' => true, \'rewrite\' => $rewrite2));