Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lokothodida/fcec531f360fbd470ada to your computer and use it in GitHub Desktop.
Save lokothodida/fcec531f360fbd470ada to your computer and use it in GitHub Desktop.
GetSimple tutorial for rendering a (i18n) custom field conditionally.

GetSimple Tutorial: i18n Custom Fields: Conditional Rendering

Oleg06 of the GetSimple forums once asked about displaying certain content from a Special/Custom field based on whether or not the field is filled.

To do this, you simply form a conditional using the return_special_field function, checking that the result (a string) is non-empty:

<?php
  if (return_special_field($field) !== '') {
    // output
  }
?>

Here are some examples of this technique in use.

Gallery

Specifically, Oleg asked about displaying a gallery if the gallery's name (supplied by a custom field) is filled. The most efficient way of doing this is to fill an array with the gallery names, loop over that array and output based on whether the special field has a value:

<?php

// List of the names of our galleries/slides
$slides = array('gall1', 'gall2', 'gall3', 'gall4');

?>

<ul class="slides">
  <?php
    // Loop through each slide and display ones that have a proper field
    foreach ($slides as $slide) {
      if (return_special_field($slide) !== '') {
        ?>
        <li>
          <?php get_special_field_image($slide); ?>
        </li>
        <?php
      }
    }
  ?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment