Do something when nothing is in the array
-
I have just downloaded Simple Fields and I think it’s fantastic. Just one query:
I am creating a custom events page and have an option to add event sponsors (fields provided by SF). Is it possible to have the sponsors section disappear if there are no meta options? Here is my code now:
<?php $event_sponsors = simple_fields_values( 'wca_events_sponsors_logo, wca_events_sponsors_name' ); if ( empty( $event_sponsors ) ) { ?> <ul id="event-sponsors-list" class="event-list"> <?php foreach( $event_sponsors as $event_sponsor ) { ?> <li style="background-image: url('<?php echo $event_sponsor['wca_events_sponsors_logo']['url']; ?>');" title="<?php echo $event_sponsor['wca_events_sponsors_name']; ?>"> </li> <?php } ?> </ul> <?php } ?>
A
var_dump
of$event_sponsors
gives:array(0) { }
so in theory,
empty()
should work. Right? Is there something I’ve missed?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Do something when nothing is in the array’ is closed to new replies.