PHP如果发出其他问题

时间:2014-03-24 16:19:24

标签: php if-statement

我确信这很简单,但如果不打破我的页面,我就无法得到这个:

<?php
   $values = get_field('testimonial_text');
      if($values) {
      echo '                
      <div class="testimonial entry-content">
      <h2><?php the_field('testimonial_title'); ?></h2>
      <?php the_field('testimonial_text'); ?>
      </div>';
  } else {
       echo '';
      }
   ?>

有人能告诉我我做错了什么以及为什么我做错了。

2 个答案:

答案 0 :(得分:8)

您已嵌套<?php .. ?>块。这表明出现了问题!

<?php
  $values = get_field('testimonial_text');
  if($values) {
    echo '<div class="testimonial entry-content">';
    echo '<h2>'; the_field('testimonial_title'); echo '</h2>';
    the_field('testimonial_text');
    echo '</div>';
  }
  // your else was a no-op, so I removed it
?>

答案 1 :(得分:0)

你已经在一个已打开的PHP块中有一个PHP块。那是行不通的。

相关问题