Skip to content

Instantly share code, notes, and snippets.

@edbentinck
Forked from hitautodestruct/readme.md
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save edbentinck/1b7af83d7f76e6adfb76 to your computer and use it in GitHub Desktop.

Select an option

Save edbentinck/1b7af83d7f76e6adfb76 to your computer and use it in GitHub Desktop.

Revisions

  1. edbentinck renamed this gist May 7, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. edbentinck revised this gist May 7, 2014. No changes.
  3. edbentinck revised this gist May 7, 2014. No changes.
  4. edbentinck revised this gist May 7, 2014. 1 changed file with 10 additions and 8 deletions.
    18 changes: 10 additions & 8 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,12 @@
    <?php
    $menu_name = 'main_nav';
    $menu_name = 'primary';
    $locations = get_nav_menu_locations();
    $menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
    $menuitems = wp_get_nav_menu_items( $menu->term_id, array( 'order' => 'DESC' ) );
    ?>

    <nav>
    <ul class="main-nav">
    <ul class="nav site-nav l-container l--fullwidth">
    <?php
    $count = 0;
    $submenu = false;
    @@ -16,7 +16,9 @@
    $id = get_post_meta( $item->ID, '_menu_item_object_id', true );
    // set up a page object to retrieve page data
    $page = get_page( $id );
    $link = get_page_link( $id );

    $title = $item->title;
    $link = $item->url;

    // item does not have a parent so menu_item_parent equals 0 (false)
    if ( !$item->menu_item_parent ):
    @@ -25,12 +27,12 @@
    $parent_id = $item->ID;
    ?>

    <li class="item">
    <li class="site-nav__item">
    <a href="<?php echo $link; ?>" class="title">
    <?php echo $page->post_title; ?>
    <?php echo $title; ?>
    </a>
    <a href="<?php echo $link; ?>" class="desc">
    <?php echo $page->post_excerpt; ?>
    <?php echo $item->post_excerpt; ?>
    </a>
    <?php endif; ?>

    @@ -41,8 +43,8 @@
    <?php endif; ?>

    <li class="item">
    <a href="<?php echo $link; ?>" class="title"><?php echo $page->post_title; ?></a>
    <a href="<?php echo $link; ?>" class="desc"><?php echo $page->post_excerpt; ?></a>
    <a href="<?php echo $link; ?>" class="title"><?php echo $itle; ?></a>
    <a href="<?php echo $link; ?>" class="desc"><?php echo $item->post_excerpt; ?></a>
    </li>

    <?php if ( $menuitems[ $count + 1 ]->menu_item_parent != $parent_id && $submenu ): ?>
  5. @hitautodestruct hitautodestruct revised this gist Mar 28, 2013. No changes.
  6. @hitautodestruct hitautodestruct revised this gist Dec 20, 2012. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -55,4 +55,7 @@
    </li>
    <?php $submenu = false; endif; ?>

    <?php $count++; endforeach; ?>
    <?php $count++; endforeach; ?>

    </ul>
    </nav>
  7. @invalid-email-address Anonymous created this gist Dec 20, 2012.
    58 changes: 58 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    <?php
    $menu_name = 'main_nav';
    $locations = get_nav_menu_locations();
    $menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
    $menuitems = wp_get_nav_menu_items( $menu->term_id, array( 'order' => 'DESC' ) );
    ?>

    <nav>
    <ul class="main-nav">
    <?php
    $count = 0;
    $submenu = false;

    foreach( $menuitems as $item ):
    // get page id from using menu item object id
    $id = get_post_meta( $item->ID, '_menu_item_object_id', true );
    // set up a page object to retrieve page data
    $page = get_page( $id );
    $link = get_page_link( $id );

    // item does not have a parent so menu_item_parent equals 0 (false)
    if ( !$item->menu_item_parent ):

    // save this id for later comparison with sub-menu items
    $parent_id = $item->ID;
    ?>

    <li class="item">
    <a href="<?php echo $link; ?>" class="title">
    <?php echo $page->post_title; ?>
    </a>
    <a href="<?php echo $link; ?>" class="desc">
    <?php echo $page->post_excerpt; ?>
    </a>
    <?php endif; ?>

    <?php if ( $parent_id == $item->menu_item_parent ): ?>

    <?php if ( !$submenu ): $submenu = true; ?>
    <ul class="sub-menu">
    <?php endif; ?>

    <li class="item">
    <a href="<?php echo $link; ?>" class="title"><?php echo $page->post_title; ?></a>
    <a href="<?php echo $link; ?>" class="desc"><?php echo $page->post_excerpt; ?></a>
    </li>

    <?php if ( $menuitems[ $count + 1 ]->menu_item_parent != $parent_id && $submenu ): ?>
    </ul>
    <?php $submenu = false; endif; ?>

    <?php endif; ?>

    <?php if ( $menuitems[ $count + 1 ]->menu_item_parent != $parent_id ): ?>
    </li>
    <?php $submenu = false; endif; ?>

    <?php $count++; endforeach; ?>