Скрыть поле, если оно пусто

  • Автор темы STRIJ1
  • 15
  • Обновлено
  • 17, May 2024
  • #1
Привет ребята,

Может ли кто-нибудь помочь мне с небольшой проблемой в моем коде? У меня есть следующие настраиваемые поля в моем файле function.php:
 <?php } $mr_trial_price_123=get_post_meta($post->ID,"mr_trial_price",true); if($mr_trial_price_123){ ?>

<li><a target="_blank" href="<?php echo $post_external_link; ?>" rel="nofollow">

<div class="pnkP" id="p1"><span>$</span>

<h5><?php echo get_post_meta($post->ID,"mr_trial_price",true); ?> <small>/trial</small></h5>

</div>

<div class="offP" id="p2">

<?php if(get_post_meta($post->ID,"mr_trial_off",true)){ ?>

<i class="prctIcon"></i> <?php echo get_post_meta($post->ID,"mr_trial_off",true); ?>% OFF

<?php } ?>

</div>

<div class="dscP" id="p3">

<?php if(get_post_meta($post->ID,"mr_trial_lastrice",true)){ ?>

<i class="curP"></i> <strike><?php echo get_post_meta($post->ID,"mr_trial_lastrice",true); ?></strike>

<?php } ?>

</div>

</a></li>
PHP: Сегодня я добавил следующие новые настраиваемые поля:
 <?php } else { if($month_price_1){ ?> <ul class="wjprice"> <li><a target="_blank" href="<?php echo $post_external_link; ?>" rel="nofollow"> <div class="pnkP" id="p1"><span>$</span> <h5><?php echo get_post_meta($post->ID,"mr_month_price",true); ?> <small>/month</small></h5> </div> <div class="offP" id="p2"> <?php $dollar_price_1= get_post_meta($post->ID,"mr_month_off",true); if($dollar_price_1){ ?> <i class="prctIcon"></i> <?php echo $dollar_price_1."% OFF"; } ?> </div> <div class="dscP" id="p3"> <?php $dollar_my= get_post_meta($post->ID,"mr_month_lastrice",true); if($dollar_my){ ?> <i class="curP"></i> <strike><?php echo $dollar_my; ?></strike> <?php } ?> </div> </a></li> <?php } $mr_sixmonth_price_12= get_post_meta($post->ID,"mr_sixmonth_price",true); if($mr_sixmonth_price_12){ ?> <li><a target="_blank" href="<?php echo $post_external_link; ?>" rel="nofollow"> <div class="pnkP" id="p1"><span>$</span> <h5><?php echo get_post_meta($post->ID,"mr_sixmonth_price",true); ?> <small>/3 month</small></h5> </div> <div class="offP" id="p2"> <?php $percentage_price_12= get_post_meta($post->ID,"mr_sixmonth_off",true); if($percentage_price_12){ ?> <i class="prctIcon"></i> <?php echo $percentage_price_12."% OFF"; } ?></div> <div class="dscP" id="p3"> <?php $my_year_123= get_post_meta($post->ID,"mr_sixmonth_lastrice",true); if($my_year_123){ ?> <i class="curP"></i> <strike><?php echo $my_year_123; ?></strike> <?php } ?> </div> </a></li> <?php } $mr_threeyear_price_123=get_post_meta($post->ID,"mr_threeyear_price",true); if($mr_threeyear_price_123){ ?> <li><a target="_blank" href="<?php echo $post_external_link; ?>" rel="nofollow"> <div class="pnkP" id="p1"><span>$</span> <h5><?php echo get_post_meta($post->ID,"mr_threeyear_price",true); ?> <small>/6 month</small></h5> </div> <div class="offP" id="p2"> <?php if(get_post_meta($post->ID,"mr_threeyear_off",true)){ ?> <i class="prctIcon"></i> <?php echo get_post_meta($post->ID,"mr_threeyear_off",true); ?>% OFF <?php } ?> </div> <div class="dscP" id="p3"> <?php if(get_post_meta($post->ID,"mr_threeyear_lastrice",true)){ ?> <i class="curP"></i> <strike><?php echo get_post_meta($post->ID,"mr_threeyear_lastrice",true); ?></strike> <?php } ?> </div> </a></li> <?php } $mr_fiveyear_price_123=get_post_meta($post->ID,"mr_fiveyear_price",true); if($mr_fiveyear_price_123){ ?> <li><a target="_blank" href="<?php echo $post_external_link; ?>" rel="nofollow"> <div class="pnkP" id="p1"><span>$</span> <h5><?php echo get_post_meta($post->ID,"mr_fiveyear_price",true); ?> <small>/1 Year</small></h5> </div> <div class="offP" id="p2"> <?php if(get_post_meta($post->ID,"mr_fiveyear_off",true)){ ?> <i class="prctIcon"></i> <?php echo get_post_meta($post->ID,"mr_fiveyear_off",true); ?>% OFF <?php } ?> </div> <div class="dscP" id="p3"> <?php $year_class_5_1= get_post_meta($post->ID,"mr_fiveyear_lastrice",true); if($year_class_5_1){ ?> <i class="curP"></i> <strike><?php echo $year_class_5_1; ?></strike> <?php } ?> </div> </a></li> <?php }?> </ul> <?php }?>
PHP: Это код, который у меня есть в моем файле Single.php:
 update_post_meta($post->ID, 'mr_trial_price', $_POST['mr_trial_price']); update_post_meta($post->ID, 'mr_trial_off', $_POST['mr_trial_off']); update_post_meta($post->ID, 'mr_trial_lastrice', $_POST['mr_trial_lastrice']);
PHP: На данный момент все работает нормально.

Первый, «mr_month_price», показывает данные, когда я помещаю текст в поле, а также в другие поля, и если текст не добавляется, они не отображаются именно так, как я хочу.

Сначала я хочу добавить новые настраиваемые поля «mr_trial_price» над «mr_month_price».

Но когда я это делаю, по какой-то причине поле «mr_month_price» тоже исчезает, когда поле «mr_trial_price» пусто...

Это код, который я использовал после строки:


  • :
     update_post_meta($post->ID, 'mr_month_price', $_POST['mr_month_price']); update_post_meta($post->ID, 'mr_month_off', $_POST['mr_month_off']); update_post_meta($post->ID, 'mr_month_lastrice', $_POST['mr_month_lastrice']); update_post_meta($post->ID, 'mr_sixmonth_price', $_POST['mr_sixmonth_price']); update_post_meta($post->ID, 'mr_sixmonth_off', $_POST['mr_sixmonth_off']); update_post_meta($post->ID, 'mr_sixmonth_lastrice', $_POST['mr_sixmonth_lastrice']); update_post_meta($post->ID, 'mr_threeyear_price', $_POST['mr_threeyear_price']); update_post_meta($post->ID, 'mr_threeyear_off', $_POST['mr_threeyear_off']); update_post_meta($post->ID, 'mr_threeyear_lastrice', $_POST['mr_threeyear_lastrice']); update_post_meta($post->ID, 'mr_fiveyear_price', $_POST['mr_fiveyear_price']); update_post_meta($post->ID, 'mr_fiveyear_off', $_POST['mr_fiveyear_off']); update_post_meta($post->ID, 'mr_fiveyear_lastrice', $_POST['mr_fiveyear_lastrice']);

    PHP: Есть идеи, что может быть?
    Что мне не хватает?

    Спасибо!!

STRIJ1


Рег
30 Jun, 2010

Тем
28

Постов
933

Баллов
1213
Тем
49554
Комментарии
57426
Опыт
552966

Интересно