ThemeShaper Forums » Thematic

[closed]

A better way to use the new Menu in Wordpress 3.0 final version

(12 posts)
  • Started 4 years ago by theorib
  • Latest reply from lxwx
  • This topic is not a support question
  1. Hi all,

    I'm posting this for those of you who might be looking on how to implement the new navigation menus that come with Wordpress 3.0

    The technique Chris posted on Thematic4you didn't seem to be working with the final WP 3.0 version so I went ahead looking for solutions:
    http://programming.thematic4you.com/2010/03/how-to-test-wp_nav_menu-with-thematic/

    With the help of the WP Codex and a great post by Justin Tadlock (links bellow) I got the new menu to work with Thematic:
    http://codex.wordpress.org/Function_Reference/wp_nav_menu
    http://justintadlock.com/archives/2010/06/01/goodbye-headaches-hello-menus

    I'm not very good with PHP so if any of you have any suggestions to improve the code they are welcome!

    // We declare that our theme supports wp_nav_menu()
    add_theme_support( 'nav-menus' );
    
    // We Register the a new menu for the theme called "Primary Menu"
    function register_primary_menu() {
    	register_nav_menu( 'primary-menu', __( 'Primary Menu' ) );
    }
    add_action( 'init', 'register_primary_menu' );
    
    // We remove the standard Thematic menu
    function remove_menu() {
    	remove_action('thematic_header','thematic_access',9);
    }
    add_action('init', 'remove_menu');
    
    // We create the new wp_nav_menu called "Primary Menu" in our theme
    function new_access() { ?>
    	<div id="access">
    		<div class="skip-link"><a href="#content" title="<?php _e('Skip navigation to the content', 'thematic'); ?>"><?php _e('Skip to content', 'thematic'); ?></a></div><!-- .skip-link -->
    
    			<?php /* Our navigation menu.  If one isn't filled out, wp_nav_menu falls back to wp_page_menu.  The menu assiged to the primary position is the one used.  If none is assigned, the menu with the lowest ID is used.  */ ?>
    			<?php wp_nav_menu( array(
                              			'theme_location' => 'primary-menu', // we define this as being the previously registered "Primary Menu"
                              			'menu_class' => 'sf-menu', // we assign the sf-menu class to the menu ul so that superfish workds
                              			'container_class' => 'menu' // we assign the menu class to the menu container div so to keep it compatible with the Thematic menu styling
                              		));
    			?>
    	</div><!-- #access -->
    <?php
    }
    add_action('thematic_header','new_access',9);
    Posted 4 years ago #
  2. Nice work. I'm reading Justin's post to get my head wrapped around this.

    also does this break everything in <wp3.0 ? i have no menus at the moment and it doesn't seem to fall back to wp_list_pages.

    Posted 4 years ago #
  3. Heads up in the final WP 3.0 things changed:

    add_theme_support( 'nav-menus' );

    needs to be:

    add_theme_support( 'menus' );

    to work properly.

    Posted 4 years ago #
  4. Thanks em hr, I'll check into that although it worked for me that way (weird)...

    I really didn't check if it breaks stuff in other version of WP @helgatheviking, but I'd say it does.

    Take a look at the last SVN version of Thematic, as far as I know Chris made it all easier for us to use those menus but I still didn't test it. take a look at the last post here:

    http://forums.themeshaper.com/topic/wordpress-30-and-the-upcoming-thematic-release

    Posted 4 years ago #
  5. This is all I am using to integrate the new nav menu's for a singular menu on WP3 + Thematic 0.9.7

    add_theme_support( 'menus' );
    
    function child_access_menu() {
    	$menu_sys = 'wp_nav_menu';
    	return $menu_sys;
    }
    add_filter('thematic_menu_type', 'child_access_menu');

    Thats pretty simple right. How simple the code is depends on how you are using the menu system with Thematic.

    Posted 4 years ago #
  6. theBlogButler
    Member

    How would I integrate a categories menu drop-down that is dynamic and not dependent upon pages?

    Posted 4 years ago #
  7. download and take a look at the code for the Commune Child theme.

    http://www.cozmoslabs.com/2009/04/07/green-anyone-try-commune-thematic-child-theme/

    it has a category menu built in

    Posted 4 years ago #
  8. theBlogButler
    Member

    I'll say it - Helga rocks! Thank you!

    Posted 4 years ago #
  9. theBlogButler
    Member

    Well this is cool but the commune theme isn't using the 3.0 menu functionality. I'm not good enough with PHP to punch the proper code into the 3.0 functionality. :(

    Posted 4 years ago #
  10. Hi,

    Heads up using add_theme_support in this way is not advised

    ref: http://forums.themeshaper.com/topic/add_theme_supportmenus

    -Gene

    Posted 4 years ago #
  11. lxwx
    Member

    OK, I'm experiencing some frustration getting this to work in a child theme built against Thematic 0.9.7.4 (latest stable dev release).

    Started with a "clean slate" child theme on a scratch site and sure enough, as Gene has mentioned elsewhere, only needed this in my functions.php to get Custom Menu working as hoped!

    function child_access_menu() {
    $menu_sys = 'wp_nav_menu';
    return $menu_sys;
    }
    add_filter('thematic_menu_type', 'child_access_menu');

    But then I tried the same thing in my original child theme, and no joy. The main menu area remains empty. When I activate stock Thematic 0.9.7.4 on this install, the Custom Menu widget renders correctly in the sidebar. But when I switch back to my child theme, this is no longer true -- the widget is empty.

    I've removed all other menu-related add_filter() and add_action() statements. I've tried re-saving the Menu, and both reset buttons in Thematic Options. Both themes say they "support 1 menu" in Appearance > Menus. It still seems like something in the data is messing this up.

    Is there some trick I'm missing? Mustn't the Custom Menu widget be working before there is any hope of getting the same menu to appear in div#access?

    Thanks to anyone with advice...

    --Alex

    Posted 4 years ago #
  12. lxwx
    Member

    I discovered my problem. Thematic is blameless. :)

    I was messing with $query to limit the categories appearing on the home page, like this:


    function child_filter_exclude_category ( $query ) {
    if ( $query->is_feed || $query->is_home ) {
    $query->set( 'cat', '3' ); // include only category 3 = News
    }
    return $query;
    }
    add_filter('pre_get_posts', 'child_filter_exclude_category');

    That was the problem, and I found a better way... on this forum, of course.

    http://forums.themeshaper.com/topic/filtering-one-category-from-index-loop#post-14812

    Cheers,

    --Alex

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.