5

Featured in DMM v1.7

Posted by Edward Caissie on July 20, 2010 in News, WordPress |

DMM = the Desk Mess Mirrored theme

Just a quick preview of one of the upcoming featured changes to the Desk Mess Mirrored theme: custom menus via the wp_nav_menu() function.

The current code for Desk Mess Mirrored version 1.6 in header.php for menus is this (cleaned up for display):

<?php if ( is_home() || is_front_page()) { ?>
	<?php wp_list_pages( 'title_li=&depth=1&include=2' ); ?>
	<?php wp_list_pages( 'title_li=&depth=1&exclude=2' ); ?>
<?php } else { ?>
	<li><a href="<?php bloginfo( 'url' ); ?>"><?php _e( 'Home', 'desk-mess-mirrored' ) ?></a></li>
	<?php wp_list_pages( 'title_li=&depth=1' ); ?>
<?php } ?>

All of that code is simply replaced by this line:

<?php dmm_nav_menu(); ?>

The function dmm_nav_menu() is referring to this section of code now found in the functions.php template file:

    // Add wp_nav_menu() custom menu support
    add_theme_support( 'menus' );
    function dmm_nav_menu() {
      if ( function_exists( 'wp_nav_menu' ) )
        wp_nav_menu( array(
                           'theme_location' => 'top-menu',
                           'depth' => 1,
                           'fallback_cb' => 'dmm_list_pages'
                           ) );
      else
        dmm_list_pages();      
    }
    
    function dmm_list_pages() {
      if ( is_home() || is_front_page() ) {
        wp_list_pages( 'title_li=&depth=1' );
      } else { ?>
        <li><a href="<?php bloginfo( 'url' ); ?>"><?php _e( 'Home', 'desk-mess-mirrored' ) ?></a></li>
        <?php wp_list_pages( 'title_li=&depth=1' );
      }
    }
    
    add_action( 'init', 'register_dmm_menu' );
    function register_dmm_menu() {
      register_nav_menu( 'top-menu', __( 'Top Menu' ) );
    }
    // wp_nav_menu() end

Notice the highlighted lines are identical which means at the default settings after updating to version 1.7 you should see no difference in how your site looks, but you are now able to set the menu links using the interface under Appearance | Menus. Also note, the menu is still set as a top-level or parent only menu. Future versions of DMM may offer drop-down menus and other options but they are not currently scheduled for a particular release date or version at this time.

All of these changes were based on the article I wrote at WPFirstAid.com titled: Upgrade wp_list_pages() to wp_nav_menu().

Enjoy!

Tags: , , ,

5 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright © 2009-2017 BuyNowShop All rights reserved.
This site is using the Custom Child-Theme, v1.0.3, on top of
the Parent-Theme Desk Mess Mirrored, v2.5, from BuyNowShop.com