Skip to content

Instantly share code, notes, and snippets.

@tomfinitely
Created April 13, 2017 16:48
Show Gist options
  • Save tomfinitely/938c04c06ac6bc04bb23c9aa64ba686c to your computer and use it in GitHub Desktop.
Save tomfinitely/938c04c06ac6bc04bb23c9aa64ba686c to your computer and use it in GitHub Desktop.
ACF-Based Restaurant Menu Template
<?php
/*
Template Name: Restuarant Menu Template2
*/
add_action( 'genesis_before_loop', 'my_restaurant_menu' );
function my_restaurant_menu () {
//My ACF Fields for reference
//menu_sections - field group
//section_items - sub-field
//section_title - sub-field
if( is_page( 381 ) ) {// restaurant template id
remove_action( 'genesis_loop', 'genesis_do_loop' );//un comment to remove default loop if loop not required
add_action( 'genesis_after_loop', 'menu_loop' );//add in the repeater loop below
function menu_loop () {
echo '<div class="entry-content dishes">';
// check if the repeater field has rows of data
if( have_rows('menu_sections') ):
// loop through the rows of data
while ( have_rows('menu_sections') ) : the_row();
// display a sub field value
echo '<h2>' . get_sub_field('section_title') . '</h2>';
if ( have_rows('sections_items'));?>
<table>
<thead>
<tr>
<td class="ja_name">Name</td>
<td class="ja_description">Description</td>
<td class="ja_price">Price</td>
</tr>
</thead>
<?php while (have_rows('section_items') ): the_row(); ?>
<tr>
<td><?php the_sub_field('dish_name'); ?></td>
<td><?php the_sub_field('dish_description'); ?></td>
<td>$ <?php the_sub_field('dish_price'); ?></td>
</tr>
<?php endwhile;?>
</table> <?php
endwhile;
else :
// no rows found
endif; ?></div><?php
}
}
}
genesis();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment