如果 h2>中没有文字,我可以删除 h2> 吗?

时间:2022-11-24 23:42:37

This is the php code I am modifying to have a header and a description text box appear above the slider. It works great if there is a header and description set within the slider, but on other pages I just want the image - instead an empty "text box" is displayed as it reads the <h2> and <br> tags.

这是我修改的php代码,在滑块上方有一个标题和一个描述文本框。如果在滑块内设置了标题和描述,它会很有效,但在其他页面上我只想要图像 - 而是显示空的“文本框”,因为它会读取


标记。

Is there anyway I can make an if .$item['itemImageTitle'] & .$item['itemTitle'] empty show just the image, if not empty show the boxes too?

无论如何我可以制作一个if。$ item ['itemImageTitle']&。$ item ['itemTitle']空显示图像,如果不是空显示框也是?

css

.nivo-caption h2 {
font-size: xx-large;
color: #fff;
}

.theme-default .nivo-caption {
    font-family: inherit;
    font-size: 16px;
    font-weight: bold;
    /* z-index: 20; */
    -moz-text-shadow: 1px 1px 0 #000;
    -webkit-text-shadow: 1px 1px 0 #000;
     text-shadow: 1px 1px 0 #000;
  position: absolute;
  left: 23px;
  bottom: 20px;
  background: rgba(58, 88, 129, 0.5);
  color: #fff;
  width: 95%;
  z-index: 8;
  padding: 5px 10px;
  opacity: 1;
  overflow: hidden;
  display: none;
  -moz-opacity: 1;
  filter: alpha(opacity=1);
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

php

<div class="slider-wrapper <?php  echo "theme-".$theme_title;?>" id="<?php  echo "slider-wrapper-".$bID; ?>">
    <div id="<?php  echo "nivo-slider-".$bID; ?>" class="nivoSlider" style="width: 100% !important;">
    <?php   
    foreach($items as $item) { 
        echo (strlen($item['itemUrl'])>1) ? '<a href="'.$item['itemUrl'].'">' : '';
        echo '<img src="'.$item['itemImageSrc'].'" alt="'.$item['itemImageAlt'].'" title="<h2>'.$item['itemTitle'].'</h2><br>'.$item['itemImageTitle'].'" data-thumb="'.$item['itemImageSrc'].'" >';
        echo (strlen($item['itemUrl'])>1) ? '</a>' : '';
    } 
    ?>

    </div>

</div>

1 个解决方案

#1


1  

As you said if .$item['itemImageTitle'] & .$item['itemTitle'] empty show just the image. You can try this

正如你所说的那样。$ item ['itemImageTitle']&。$ item ['itemTitle']空显示只是图像。你可以试试这个

<div class="slider-wrapper <?php  echo "theme-".$theme_title;?>" id="<?php  echo "slider-wrapper-".$bID; ?>">
    <div id="<?php  echo "nivo-slider-".$bID; ?>" class="nivoSlider" style="width: 100% !important;">
    <?php   
    foreach($items as $item) { 
        echo (strlen($item['itemUrl'])>1) ? '<a href="'.$item['itemUrl'].'">' : '';

        $my_title = "";
        if(!empty($item['itemImageTitle']) && !empty($item['itemTitle'])){
           $my_title = '<h2>'.$item['itemTitle'].'</h2><br>'.$item['itemImageTitle'].'</h2>';

        }


        echo '<img src="'.$item['itemImageSrc'].'" alt="'.$item['itemImageAlt'].'" title="'.$my_title.'" data-thumb="'.$item['itemImageSrc'].'" >';
        echo (strlen($item['itemUrl'])>1) ? '</a>' : '';
    } 
    ?>

    </div>

</div>

#1


1  

As you said if .$item['itemImageTitle'] & .$item['itemTitle'] empty show just the image. You can try this

正如你所说的那样。$ item ['itemImageTitle']&。$ item ['itemTitle']空显示只是图像。你可以试试这个

<div class="slider-wrapper <?php  echo "theme-".$theme_title;?>" id="<?php  echo "slider-wrapper-".$bID; ?>">
    <div id="<?php  echo "nivo-slider-".$bID; ?>" class="nivoSlider" style="width: 100% !important;">
    <?php   
    foreach($items as $item) { 
        echo (strlen($item['itemUrl'])>1) ? '<a href="'.$item['itemUrl'].'">' : '';

        $my_title = "";
        if(!empty($item['itemImageTitle']) && !empty($item['itemTitle'])){
           $my_title = '<h2>'.$item['itemTitle'].'</h2><br>'.$item['itemImageTitle'].'</h2>';

        }


        echo '<img src="'.$item['itemImageSrc'].'" alt="'.$item['itemImageAlt'].'" title="'.$my_title.'" data-thumb="'.$item['itemImageSrc'].'" >';
        echo (strlen($item['itemUrl'])>1) ? '</a>' : '';
    } 
    ?>

    </div>

</div>