Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mikeott/a24cec5184ee5247ec09d611349c45c5 to your computer and use it in GitHub Desktop.
Save mikeott/a24cec5184ee5247ec09d611349c45c5 to your computer and use it in GitHub Desktop.
WordPress shortcode for template and editor usage
<?php /*
Board of Directors.
Template usage: <?php echo do_shortcode('[board_of_directors]'); ?>
Editor usage: Add a shortcode: [board_of_directors]
*/
function board_of_directors_code() {
if( have_rows('directors', 19) ) {
while( have_rows('directors', 19) ) : the_row();
$name = get_sub_field('name', 19);
$title = get_sub_field('title', 19);
$skill = get_sub_field('skill', 19);
$independent = get_sub_field('independent', 19);
$doar = get_sub_field('doar', 19);
if($independent) {
$independence = 'Yes: ';
} else {
$independence == 'No: ';
}
$rows .= '<tr><td>' . $name . '</td><td>' . $independence . $title . '</td><td>' . $skill . '</td><td>' . $doar . '</td></tr>';
endwhile;
$table_start = '<table><tr><th>Director</th><th>Independent</th><th>Skill</th><th>Appointment/resignation date</th></tr>';
$table_end = '</table>';
return $table_start . $rows . $table_end;
} else {
/* Do nothing */
}
}
add_shortcode('board_of_directors', 'board_of_directors_code');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment