Skip to content

Instantly share code, notes, and snippets.

@vinnycrazzy
Forked from hitautodestruct/readme.md
Created May 5, 2022 15:08
Show Gist options
  • Select an option

  • Save vinnycrazzy/d2e6f74564d3d51abfa123ed157fd2b1 to your computer and use it in GitHub Desktop.

Select an option

Save vinnycrazzy/d2e6f74564d3d51abfa123ed157fd2b1 to your computer and use it in GitHub Desktop.

Revisions

  1. @hitautodestruct hitautodestruct revised this gist Mar 31, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    This gist is for showing an example of a custom wordpress menu.

    If you want to get more from the menu item simply have a look at the $item object.
    i.e:

    // Will return a large object with lots of props like title, url, description, id etc.
    var_dump( $item );

    This code works on Wordpress 4.1.1 as of 31st of March 2015
  2. @hitautodestruct hitautodestruct revised this gist Mar 31, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    If you want to get more from the menu item simply have a look at the $item object.
    i.e:

    // Will return a large object with lots of props like title, url, description, id etc.
    var_dump( $item );

  3. @hitautodestruct hitautodestruct revised this gist Mar 31, 2015. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,5 @@
    If you want to get more from the menu item simply have a look at the $item object.
    i.e:

    ### Will return a large object with lots of props like title, url, description, id etc.
    // Will return a large object with lots of props like title, url, description, id etc.
    var_dump( $item );

  4. @hitautodestruct hitautodestruct revised this gist Mar 31, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    If you want to get more from the menu item simply have a look at the $item object.
    i.e:

    // Will return a large object with lots of props like title, url, description, id etc.
    var_dump( $item );
    ### Will return a large object with lots of props like title, url, description, id etc.
    var_dump( $item );

  5. @hitautodestruct hitautodestruct revised this gist Mar 31, 2015. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    If you want to get more from the menu item simply have a look at the $item object.
    i.e:

    // Will return a large object with lots of props like title, url, description, id etc.
    var_dump( $item );

  6. @hitautodestruct hitautodestruct renamed this gist Mar 31, 2015. 1 changed file with 4 additions and 11 deletions.
    15 changes: 4 additions & 11 deletions gistfile1.php → wp_custom_nav.php
    Original file line number Diff line number Diff line change
    @@ -12,12 +12,9 @@
    $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 );

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

    @@ -27,10 +24,7 @@

    <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; ?>
    <?php echo $title; ?>
    </a>
    <?php endif; ?>

    @@ -41,8 +35,7 @@
    <?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 $title; ?></a>
    </li>

    <?php if ( $menuitems[ $count + 1 ]->menu_item_parent != $parent_id && $submenu ): ?>
  7. @hitautodestruct hitautodestruct revised this gist Mar 28, 2013. No changes.
  8. @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>
  9. @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; ?>