当元数据为空时,我怎么能隐藏图像(.png)

时间:2015-06-05 19:12:56

标签: php html wordpress

我希望按钮隐藏,当它为空时仍然不幸只有HTML之前,即使按钮已经是空的,我怎么能重写代码以便隐藏按钮?我发布了更多细节,也许有人可以帮助我

        function cspm_infobox_content(){

        $post_id = esc_attr($_POST['post_id']);
        $infobox_type = esc_attr($_POST['infobox_type']);
        $map_id = esc_attr($_POST['map_id']);
        $status = esc_attr($_POST['status']);
        $carousel = esc_attr($_POST['carousel']);
        $telnr = get_post_meta( $post_id, 'telnr', true );
        $telnr1 = get_post_meta( $post_id, 'telnr1', true );
        $email = get_post_meta( $post_id, 'email', true );
        $hane = get_post_meta( $post_id, 'hane', true );
        $marte = get_post_meta( $post_id, 'marte', true );
        $merkure = get_post_meta( $post_id, 'merkure', true );
        $enjte = get_post_meta( $post_id, 'enjte', true );
        $premte = get_post_meta( $post_id, 'premte', true );
        $shtune = get_post_meta( $post_id, 'shtune', true );
        $djele = get_post_meta( $post_id, 'djele', true );
        $shteti = get_post_meta( $post_id, 'shteti', true );
        $qyteti = get_post_meta( $post_id, 'qyteti', true );
        $rajoni = get_post_meta( $post_id, 'rajoni', true );
        $rruganr = get_post_meta( $post_id, 'rruganr', true );

        $no_title = array(); // Infoboxes to display with no title
        $no_link = array(); // Infobox to display whit no link
        $no_description = array('square_bubble', 'rounded_bubble', 'cspm_type2', 'cspm_type3', 'cspm_type4'); // Infoboxes to display with no description
        $no_image = array('cspm_type4'); // Infoboxes to display with no image



        if(!in_array($infobox_type, $no_title)) $item_title = apply_filters('cspm_custom_infobox_title', stripslashes_deep($this->cspm_items_title($post_id, $this->items_title)), $post_id); 
        if(!in_array($infobox_type, $no_description)) $item_description = apply_filters('cspm_custom_infobox_description', stripslashes_deep($this->cspm_items_details($post_id, $this->items_details)), $post_id);
        if(!in_array($infobox_type, $no_link)) $the_permalink = $this->cspm_get_permalink($post_id);

        if(!in_array($infobox_type, $no_image)){

            if($infobox_type == 'square_bubble' || $infobox_type == 'rounded_bubble')
                $parameter = array( 'style' => "width:50px; height:50px;" );
            elseif($infobox_type == 'cspm_type1')
                $parameter = array( 'style' => "width:100px; height:80px;" );
            elseif($infobox_type == 'cspm_type2')
                $parameter = array();
            elseif($infobox_type == 'cspm_type3' || $infobox_type == 'cspm_type5')
                $parameter = array( 'style' => "width:60px; height:60px;" );
            elseif($infobox_type == 'cspm_type4')
                $parameter = array();

            if($infobox_type == 'square_bubble' || $infobox_type == 'rounded_bubble'){
                $infobox_thumb = get_the_post_thumbnail($post_id, 'cspacing-marker-thumbnail', $parameter);
            }elseif($infobox_type == 'cspm_type1'){
                $infobox_thumb = get_the_post_thumbnail($post_id, 'cspacing-infobox1-thumbnail', $parameter);
            }else $infobox_thumb = get_the_post_thumbnail($post_id, 'cspacing-horizontal-thumbnail', $parameter);

            if(empty($infobox_thumb))
                $infobox_thumb = get_the_post_thumbnail($post_id, 'cspacing-horizontal-thumbnail', $parameter);

        }

        $post_thumbnail = apply_filters('cspm_infobox_thumb', $infobox_thumb, $post_id, $infobox_type, $parameter);

        $this->infobox_external_link = $this->cspm_get_setting('infoboxsettings', 'infobox_external_link', 'same_window');

        $target = ($this->infobox_external_link == 'new_window') ? ' target="_blank"' : ''; 
        $the_post_link = ($this->infobox_external_link == 'disable') ? $item_title : '<a href="'.$the_permalink.'" title="'.$item_title.'"'.$target.'>'.$item_title.'</a>'; 

        $output = '';

        $output .= '<div class="cspm_infobox_content_container '.$status.' infobox_'.$map_id.' '.$infobox_type.'" data-map-id="'.$map_id.'" data-post-id="'.$post_id.'" data-show-carousel="'.$carousel.'">';

            if($infobox_type == 'square_bubble' || $infobox_type == 'rounded_bubble'){

                $output .= '<div class="cspm_infobox_img">';
                    $output .= ($this->infobox_external_link != 'disable') ? '<a href="'.$the_permalink.'" title="'.$item_title.'"'.$target.'>'.$post_thumbnail.'</a>' : $post_thumbnail;
                $output .= '</div>';
                $output .= '<div class="cspm_arrow_down '.$infobox_type.'"></div>';

            }elseif($infobox_type == 'cspm_type1'){

                $output .= '<div class="cspm_infobox_img">'.$post_thumbnail.'</div>';
                $output .= '<div class="cspm_infobox_content">';
                    $output .= '<div class="title">'.$the_post_link.'</div>';
                    $output .= '<div class="description">'.$item_description.'</div>';
                $output .= '</div>';
                $output .= '<div style="clear:both"></div>';
                $output .= '<div class="cspm_arrow_down"></div>';

            }elseif($infobox_type == 'cspm_type2'){

                $output .= '<div class="cspm_infobox_img">'.$post_thumbnail.'</div>';
                $output .= '<div class="cspm_infobox_content">';
                    $output .= '<div class="title">'.$the_post_link.'</div>';
                $output .= '</div>';
                $output .= '<div class="cspm_arrow_down"></div>';

            }elseif($infobox_type == 'cspm_type3'){

                $output .= '<div class="cspm_infobox_img">'.$post_thumbnail.'</div>';
                $output .= '<div class="cspm_infobox_content">';
                    $output .= '<div class="title">'.$the_post_link.'</div>';
                $output .= '</div>';
                $output .= '<div class="cspm_arrow_down"></div>';

            }elseif($infobox_type == 'cspm_type4'){

                $output .= '<div class="cspm_infobox_content">';
                    $output .= '<div class="title">'.$the_post_link.'</div>';
                $output .= '</div>';
                $output .= '<div class="cspm_arrow_down"></div>';

            /**
             * @since 2.7 */

            }elseif($infobox_type == 'cspm_type5'){

                $output .= '<div class="cspm_infobox_content">';
                    $output .= '<div>';
                        $output .= '<div class="cspm_infobox_img">'.$post_thumbnail.'</div>';
                        $output .= '<div class="title">'.$the_post_link.'</div>';
                        $output .= '<div class="telnr"><a class="wm-button color-read" href="tel:'.$telnr.'"><img src="http://test.com/test/wp-content/uploads/2015/06/Phone-18-18-dimenzionet.png" height="18" width="18"></a>';
                        $output .= '<a class="wm-button color-read telnr1" style="left: 10px;" href="tel:'.$telnr1.'"><img src="http://test.com/test/wp-content/uploads/2015/06/Phone-18-18-dimenzionet.png" height="18" width="18"></a>';
                        $output .= '<a class="wm-button color-blue email" style="left: 20px;" href="mailto:'.$email.'?Subject=Un%20jam%20informuar%20për%20ju%20nga%20www.test.com&nbsp;"><img src="http://test.com/pinfo/wp-content/uploads/2015/06/email-ico.png" height="18" width="18"></a></div>';

1 个答案:

答案 0 :(得分:0)

如果值$ telnr1为空,我想要隐藏在

下面的整个HTML
<a class="wm-button color-read telnr1" style="left: 10px;" href="tel:'.$telnr1.'"><img src="../../wp-content/uploads/2015/06/Phone-18-18-dimenzionet.png" height="18" width="18"></a>