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.
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>