WordPress

plugins — Czy możliwe jest uwzględnienie znaczników w instrukcjach If Then Else?

  • 18 czerwca, 2023
  • 3 min read
plugins — Czy możliwe jest uwzględnienie znaczników w instrukcjach If Then Else?


Próbuję dodać instrukcję else do instrukcji if, która ma pętlę foreach. Kiedy dodałem instrukcję else, po prostu renderuje pustą stronę bez błędu. Kiedyś działało przed instrukcją else.

Oto mój kod:

<?php if ( $locations ) { ?>
  <?php foreach ( $locations as $index => $location ) { ?>
    <div class="location-item" data-index="<?php echo $index; ?>">
      <input type="text" name="guide-locations-<?php echo $index; ?>-name" placeholder="Name" value="<?php echo $location['name']; ?>">
      <?php
      $editor_content = $location['description'];
      $editor_id = 'guide-locations-' . $index . '-description';
      $settings = array(
        'textarea-name' => 'guide-locations-' . $index . '-description',
        'media-buttons' => true,
        'textarea-rows' => 5,
        'tinymce' => array(
          'toolbar1' => 'formatselect | bold italic underline strikethrough | alignleft aligncenter alignright | bullist numlist | blockquote | link unlink | | pastetext removeformat | code',
          'toolbar2' => '',
          'toolbar3' => '',
          'toolbar4' => '',
        ),
      );
      wp-editor( $editor_content, $editor_id, $settings );
      ?>
      <input type="text" name="guide-locations-<?php echo $index; ?>-map" placeholder="Google Maps Embed Code" value="<?php echo $location['map']; ?>">
      <a href=" class="dashicons dashicons-info"></span></a>
      <label> Wi-Fi Available</label> <input type="checkbox" name="guide-locations-<?php echo $index; ?>-wifi" <?php checked( $location['wifi'], true ); ?>>
      <input type="text" name="guide-locations-<?php echo $index; ?>-price" placeholder="Price" value="<?php echo $location['price']; ?>">
      <input type="text" name="guide-locations-<?php echo $index; ?>-hours" placeholder="Store Hours" value="<?php echo $location['hours']; ?>">
      <button class="location-delete-button button" data-index="<?php echo $index; ?>">Delete</button>
    </div>
  <?php } ?>
<?php } else { ?>
    <div class="location-item" data-index="0">
      <input type="text" name="guide-locations-0-name" placeholder="Name" value="0">
      <?php
      $editor_content="";
      $editor_id = 'guide-locations-0-description';
      $settings = array(
        'textarea-name' => 'guide-locations-0-description',
        'media-buttons' => true,
        'textarea-rows' => 5,
        'tinymce' => array(
          'toolbar1' => 'formatselect | bold italic underline strikethrough | alignleft aligncenter alignright | bullist numlist | blockquote | link unlink | | pastetext removeformat | code',
          'toolbar2' => '',
          'toolbar3' => '',
          'toolbar4' => '',
        ),
      );
      wp-editor( $editor_content, $editor_id, $settings );
      ?>
      <input type="text" name="guide-locations-0-map" placeholder="Google Maps Embed Code" value="0">
      <a href=" class="dashicons dashicons-info"></span></a>
      <label> Wi-Fi Available</label> <input type="checkbox" name="guide-locations-0-wifi">
      <input type="text" name="guide-locations-0-price" placeholder="Price" value="0">
      <input type="text" name="guide-locations-0-hours" placeholder="Store Hours" value="0">
      <button class="location-delete-button button" data-index="0">Delete</button>
    </div>
<?php } ?>


Źródło

Warto przeczytać!  Plusy i minusy rozwiązania cenowego