Skip to content

Instantly share code, notes, and snippets.

@fourstacks
Created March 27, 2014 12:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fourstacks/9806658 to your computer and use it in GitHub Desktop.
Save fourstacks/9806658 to your computer and use it in GitHub Desktop.
Mega menu using nested ACF repeaters/flex
<?php
// check parent repeater
if( have_rows('parent_navigation_items', 'options') ):
echo '<ul class="nav primary-header-nav">';
// loop parent items
while ( have_rows('parent_navigation_items', 'options') ) : the_row();
echo '<li>';
// Get parent item post object and link text
$parent_post = get_sub_field('parent_link');
$parent_link_text = get_sub_field('parent_link_text');
// output parent link
echo '<a href="' . get_permalink( $parent_post->ID ) . '">' . $parent_link_text . '</a>';
// check if parent has child items
if( have_rows('children') ):
echo '<ul class="child_items">';
// loop child items
while ( have_rows('children') ) : the_row();
// if highlight panel layout
if( get_row_layout() == 'highlight_panel' ):
// get highlight post object and panel text
$panel_post = get_sub_field('panel_link');
$panel_text = get_sub_field('panel_text');
// output panel
echo '<li class="panel">';
echo '<a href="' . get_permalink($panel_post->ID) . '">';
echo '<h3>'.get_the_title($panel_post->ID).'</h3>';
echo '<p>'. $panel_text .'</p>';
echo '</a>';
echo '</li>';
// endif highlight panel layout
endif;
// if mini image links (e.g. sector links) layout
if( get_row_layout() == 'mini_image_links' ):
// get mini links menu title
$mini_link_title = get_sub_field('mini_images_title');
echo '<li class="mini_images">';
echo '<h3>'.$mini_link_title.'</h3>';
echo '<ul>';
// check if mini image links repeater has rows
if( have_rows('mini_image_links') ):
// loop mini image links repeater
while ( have_rows('mini_image_links') ) : the_row();
// get link post object, and set variable for mini image
$link_post = get_sub_field('link');
var_dump($link_post); // THIS RETURNS bool(FALSE) for each row (e.g. 8 times in this instance)
/* COMMENTING OUT FOR DEBUG PURPOSES
$link_post_menu_img = get_sub_field('main_menu_image', $link_post->ID);
$link_post_banner_img = get_sub_field('banner_image', $link_post->ID);
$link_post_image = ($link_post_menu_img != null ? $link_post_menu_img : $link_post_banner_img);
// output panel
echo '<li>';
echo '<a href="' . get_permalink($panel_post->ID) . '">';
echo '<figure>';
//if($link_post_image){ echo '<img src"'.$link_post_image['sizes'][''].'" />'; }
echo '</figure>';
echo '<p>'.get_the_title($link_post->ID).'</p>';
echo '</a>';
echo '</li>';
*/
// end mini image links repeater loop
endwhile;
// endif mini image links repeater has rows
endif;
echo '</ul>';
echo '</li>';
// endif mini image links layout
endif;
// end children loop
endwhile;
echo '</ul>';
// endif has children
endif;
echo '</li>';
// end loop parent items
endwhile;
echo '</ul>';
// no parent items
else :
echo 'nada';
// end if parent items
endif;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment