Last active
June 30, 2016 02:50
-
-
Save tripflex/1c59947462a7d127c254 to your computer and use it in GitHub Desktop.
Foreach PHP loop to customize output of taxonomy or field that is saved as an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$sh_indoor_outdoor = get_job_field( 'indoor_outdoor' ); | |
if( is_array( $sh_indoor_outdoor ) && ! empty( $sh_indoor_outdoor ) ){ | |
foreach( $sh_indoor_outdoor as $value ){ | |
// Go to next item if $value is an empty string, 0, false, or empty array | |
if( empty( $value ) ) continue; | |
// This switch statement checks the value to see what the class needs to be set to | |
// for the icon based on the value. You can add more by copy paste the "case" code block | |
// set the default to an icon you want to use if the value does not match any of your case statements | |
switch ($value) { | |
case 'pools': | |
$icon = 'icon-pools'; | |
break; | |
case 'bars': | |
$icon = 'icon-bars'; | |
break; | |
default: | |
$icon = 'icon-default'; | |
} | |
// This will output HTML including icon class, value of $icon, then actual value, followed by a line break <br /> | |
echo "<i class=\"icon {$icon}\"></i>{$value}<br />"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment