ThemeShaper Forums » Thematic

[closed]

Calling a WP 3.0 menu

(7 posts)
  • Started 7 years ago by Andrew
  • Latest reply from Andrew
  • This topic is resolved
  1. Hi Folks,
    I'm adding a custom field for the client to be able to click a checkbox on the pages they'd like to insert a footer navigation menu (on the long pages). I'm currently calling

    wp_nav_menu();

    and it spits out the menu just perfect, but without the sweet standard Thematic styling (.sf-menu and more..) What function should I call to pull the thematic 3.0 menu that I'm using as the main navigation?
    I've tried using

    wp_nav_menu(thematic_nav_menu_args());

    but this doesn't work, and I'm wondering if the menu args for Theme location
    are not allowing this menu to be called into this new location? Do I need to register another menu then? Even though it's the same menu I want, but just to put it in a new location?

    Thanks for your help?

    Posted 7 years ago #
  2. Hi Andrew,

    Here's the rub. If you use wp_nav_menu with thematic_nav_menu_args then you are simply displaying the same menu in the footer as you have in the header. You would need to pass a unique theme_location argument when you call wp_nav_menu to get a unique menu in the footer. Also I don't think you can use a custom field ( i.e. the "meta" arguments) with the new nav function.

    Another thing if you don't have a custom nav menu in the admin set for the theme_location argument passed to wp_nav_menu then you will fall back to wp_page_menu which doesn't get themenu_class parameter thatwp_nav_menuhas. This is probably why you're not getting the .sf-menu styling. The thematic_access() function shows how to set a condition to display one menu or the other without using the fallback argument.

    The good news is that wp_page_menu will accept arguments to wp_list_pages parameters like meta_key and meta_value
    Try this:

    function child_theme_footer_nav() {
    	$args = array (
    			'sort_column' => 'menu_order',
    			'menu_class'  => 'menu',
    			'include'     => '',
    			'exclude'     => '',
    			'echo'        => FALSE,
    			'show_home'   => FALSE,
    			'link_before' => '',
    			'link_after'  => '',
    			'meta_key' 	  => 'menu'
    
    		);
    
    	echo (thematic_add_menuclass(wp_page_menu($args)));
    }
    add_action('thematic_footer','child_theme_footer_nav');

    So a custom field key of menu with any value will now cause the page to appear in the footer.

    Also there is a bug in the current release 0.9.7.7 that will cause problem with the code i have posted. this will fix it:

    function thematic0977_bugfix() {
    	remove_filter('wp_page_menu_args','thematic_page_menu_args');
    }
    add_action('init','thematic0977_bugfix');

    This will be resolved in the upcoming release and this bugfix function can then be removed.

    -Gene

    Posted 7 years ago #
  3. Hi Gene,
    Thanks for your awesome response. I see my design training highly reducing my ability to comprehend this completely :-)

    If you use wp_nav_menu with thematic_nav_menu_args then you are simply displaying the same menu in the footer as you have in the header.

    This is exactly what I want to do! In the next sentence you state that I'll have to pass another theme_location arg if I want a 'unique' menu in the footer. But I don't want a unique menu do I? Just the same as the primary nav. As Above, so below..

    I don't actually use any custom field 'meta' in the menu array. Basically I just created a function that ask's whether the custom field checkbox is returning 'true', if so then execute my insert_footer_nav function.

    I'd rather not use wp_page_menu for this right now, because the site will continue to grow as the client creates more content, and I rather not have to filter the menu pages in the future (some being hidden, etc..) if possible. Rather just to re-create the primary nav and have them control that with the new 3.0 WP Nav menu's admin.

    Sorry for my thick headedness. I'm sure one more response and I'll be good to go :-)

    Posted 7 years ago #
  4. Ah I think I get it now. I totally misunderstood your use of custom fields. Classic, I think I'm clever and then down the rabbit hole once again lol

    So you have a custom field the when set will trigger the nav in the footer for that page, i think?

    if ((function_exists("has_nav_menu")) && (has_nav_menu(apply_filters('thematic_primary_menu_id', 'primary-menu')))) {
    	    		echo  wp_nav_menu(thematic_nav_menu_args());
        		} else {
        			echo  thematic_add_menuclass(wp_page_menu(thematic_page_menu_args()));
        		}

    this should work for you inside your conditional statement

    Posted 7 years ago #
  5. Gene, I am very grateful for your responses. In the end I've managed to get

    wp_nav_menu(thematic_nav_menu_args());

    to work on its own. I'm not sure what I have done different than at my first post when I described this was not working. Here's my code

    /*  Create the Footer Menu If Custom Field is TRUE  */
    function tc_footerMenu () {
    	$footmenu = get_post_meta(get_the_id(), '_tc_footerMenu', true);
    	$has_footmenu = ($footmenu ? true : false);
    	if ($has_footmenu): ?>
        	<div id="footerNav">
            	<?php
    			 echo  wp_nav_menu(thematic_nav_menu_args());
        		 ?>
                </div>
                <?php endif;
    }
    add_action('thematic_abovefooter', 'tc_footerMenu');

    It nos spits out the main nav at the Footer position with all the SF styling and the whole she-bang.
    Can you see any loopholes or major faults with this? Because I wasn't using a function but just checking the variable for it's return I had trouble applying your solution above. I'm super green with PHP :-) But again, I thank you profusely for your help and any issues you might see with the code here.
    Peace!

    Posted 7 years ago #
  6. The problem with that is that if you don't have a menu registered to that menu theme location wp_nav_menu will fall back to using wp_page_menu.

    It won't have the correct menu class and will not get the .sf-menu treatment.

    Try removing your menu from the "Primary" theme location in the menu admin and see what happens. The footer nav will probably lose its styling.

    Replacing echo wp_nav_menu(thematic_nav_menu_args()); with the last bit of code I offered will account for this and provide the correct classes

    Posted 7 years ago #
  7. You're dead on. I removed 'Primary' Theme location and the bottom menu turned into a ugly 5 headed monster. Putting you're code in, tames the beast put on the nice SF styling and only a few hidden pages appear. A superior option!

    Thank you again Gene!

    Posted 7 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.