ThemeShaper Forums » Thematic

[sticky] [closed]

Thematic Menus Demystified

(134 posts)
  • Started 13 years ago by helgatheviking
  • Latest reply from faeree
  • This topic is not a support question
  1. Menus seem to generate the most questions and since there have been many threads in the last couple of days, i have decided to lump all the stuff I have together in 1 place. All the functions go in the functions.php file of your child folder! The style rules i have included go in your child's style.css. If it is deemed worthy, perhaps it can get stickied.

    If you see any code errors, point them out. But if you need support or are having issues, I think creating your own thread would be best. That way, future people won't need to wade through everything to get to updates to this post. (not that significant wading isn't required for this post... it is long!).

    Things I am going to cover:
    1. Moving the menu
    2. Adding a Home link
    3. using a single wordpress 3.0 menu
    4. filter your 3.0 menu's arguments
    5. use more than one 3.0 menu
    6. css styling
    7. filtering away superfish dropdowns
    8. modifying superfish to show little arrows to indicate a sub menu

    edit Jan 07, 2012:
    Removing instructions for version 0.9.7.4 as thematic is at 0.9.7.7 in the WP repo and I advise you to use 0.9.8 which is available at:
    http://developing.thematic4you.com/thematic-development-release/

    And lets begin...

    1. Moving the Menu above the header

    moving the default menu is a matter of removing the respsonible function (in this case thematic_access() ) from its current position and adding it back to a different hook.

    // Remove the standard Thematic menu
    function remove_menu() {
    	remove_action('thematic_header','thematic_access',9);
    }
    add_action('init', 'remove_menu');
    
    // Moving the thematic menu above the header
    add_action('thematic_aboveheader','thematic_access');

    you could also re-write the whole access function, but i don't do this often anymore, so i will refer you to Ian's post instead to attempt to keep this thread under control
    http://themeshaper.com/wordpress-menu-tricks/

    2. Adding a Home Link

    Switching the default wp_list_pages() menu to wp_page_menu so that a home link can be added. because this changed between the old and new versions of thematic i will do it both ways.

    Thematic 0.9.7.4+
    When filtering wp_page_menu_args, the echo parameter must now be set to FALSE. Chris explains why here:

    http://developing.thematic4you.com/2010/04/breaking-things-to-fix-others/

    just know that it has to do w/ adding the sf-menu class to the ul that contains the menu. w/o that sf-menu class you will probably notice that your menu loses all its default style.

    // Adds a home link to your menu in Thematic 0.9.7.4
    function childtheme_menu_args($args) {
    	$args = array(
    		'show_home' => 'Home',
    		'sort_column' => 'menu_order',
    		'menu_class' => 'menu',
    		'echo' => false
    	);
    	return $args;
    }
    add_filter('wp_page_menu_args','childtheme_menu_args');

    Thematic 0.9.7.7+
    You can also add a home link (or anything) to your custom menu by filtering wp_nav_menu_items() as instructed here:
    http://wpfirstaid.com/2010/10/extend-the-wordpress-menu/

    // Filter wp_nav_menu() to add additional links and other output
    function new_nav_menu_items($items) {
    	$current = is_home() ? 'current-menu-item' : '';
    	$homelink = '<li class="home menu-item'.$current.'"><a href="' . home_url( '/' ) . '">' . __('Home') . '</a>';
    	$items = $homelink . $items;
    	return $items;
    }
    add_filter( 'wp_nav_menu_items', 'new_nav_menu_items' );

    you don't really need this for 'home' any more. As of WP 3.3 you can add a Home Link directly from your WP custom menu (it is under Pages), but it is still very useful for adding anything to your menu.

    3. Wordpress 3.0 Menus for Thematic

    My favorite resource on 3.0 menus is:
    http://justintadlock.com/archives/2010/06/01/goodbye-headaches-hello-menus

    If you are using Thematic 0.9.8, then you don't need to do any coding in order to use WP's 3.0-style menu. You only need to create a menu and set it in the 'Primary' position. Thematic will take care of the rest.
    http://developing.thematic4you.com/thematic-development-release/

    some older posts and tutorials will mention needing to use

    add_theme_support( 'nav-menus');
    //OR
    add_theme_support( 'menus' );

    in order to activate menus. but this is now NOT advised.
    http://forums.themeshaper.com/topic/add_theme_supportmenus

    the following is all you need to get a single 3.0 menu to replace the default thematic #access menu.

    Enable 1 wordpress 3.0 Menu in Thematic 0.9.7.7

    if you are still using 0.9.7.7 (and WHY? when so many bugs have been fixed in 0.9.8?) then you might need to switch the thematic access to use the 3.0-style menus.

    // change Thematic #access menu for a Wordpress 3.0 menu
    function child_access_menu() {
    	$menu_sys = 'wp_nav_menu';
    	return $menu_sys;
    }
    add_filter('thematic_menu_type', 'child_access_menu');
    Posted 13 years ago #
  2. 4. filter the menu arguments

    this is what you'd do if you wanted to change something about the new nav menu. for example you could restrict the theme to only 2 levels of drop down so some nut doesn't add 5 levels and give you a css nightmare.

    if no menus are selected or created then it will fallback automagically to wp_page_menu. i am fairly certain this means you can't break pre-worpress 3.0 sites, but don't quote me on that one. i wanted to show how to create a custom fallback function, but i can't get it working the way i want... and i am tired of menus now. it is mostly relevant anyway if you were releasing themes.

    for a full list of arguments check the codex:
    http://codex.wordpress.org/Function_Reference/wp_nav_menu

    //change menu arguments
    function menu_args( $args ) {
    $args = array( 'menu_class' => 'sf-menu', //default class that will apply default styles
    		'container_class' => 'menu', //default class
    		'depth' => 2, //limit the drop downs to only 2nd level
    	);
    return $args;
    }
    add_filter( 'thematic_nav_menu_args', 'menu_args' );

    5. Use more than 1 Menu

    if you want to use multiple menus you have to first register them using register_nav_menus(). since we're registered multiple menus it is easiest to use an array. note- you don't actually have to register the Primary Menu here if you are using the above code that changes the default thematic menu to a 3.0 menu. that is automatically the Primary Menu. I am leaving it here b/c it keeps the Primary Menu at the top of the pile in the backend on the Menus Page.

    'sample-menu' => __( 'Sample Menu' )

    the 'sample-menu' is how you will reference it in your functions file and the __('Sample Menu') is how it will appear in the backend... the __ makes it translatable.

    here's an example:

    // Register the new menus
    function register_my_menus() {
    	register_nav_menus(
    		array(
    			'primary-menu' => __( 'Primary Menu' ),
    			'top-menu' => __( 'Top Menu' ),
    
    		)
    	);
    }
    add_action( 'init', 'register_my_menus' );

    then, for example, to place an optional 2nd menu at the top of the page

    ///Top Menu (optional)
    function top_menu() {
    
       if ( has_nav_menu( 'top-menu' ) ) {
    	wp_nav_menu( array( 'theme_location' => 'top-menu',
    				'container_id'=>'top-menu',
    				'container_class' => 'clearfix ',
                    'menu_class' => 'sf-menu', // we assign the sf-menu class to the menu ul so that superfish works on this menu too
                    ) );
    
        }
    }
    
    add_action('thematic_aboveheader','top_menu');

    and now for the pièce de resistance... vive le resistance! oh... been listening to Les Mis as I work on this. onward.

    Posted 13 years ago #
  3. 6. Styling the Beast

    building off of Robo's post:
    http://forums.themeshaper.com/topic/solving-the-superfish-nightmare

    i have created the following CSS that creates an ugly as sin menu, but one that is commented and color-coded to help you find the bits you want to change. You can use this to replace the default Thematic Skin

    /*** COLOR SKIN ***/
    
    /* main ul element */
    .sf-menu {
        border-right: 1px solid FUCHSIA;
    	float:left;
    }
    
    /* general link styles*/
    .sf-menu a {
    	display: block;
    	padding:9px 13px;
    	text-decoration:none;
    	border-top: 1px solid;
    	border-left: 1px solid;
    	border-bottom: 1px solid;
    }
    
    /*** 1st Level ***/
    
    /* 1st level links, no hover, no visits */
    .sf-menu li a {
    	color: yellow;
    	background-color: green;
    	border-color: red;
    }
    /* 1st level links, while hovering over sub menu */
    .sf-menu li.sfHover a{
    	color: black;
    	background-color: silver;
    }
    
    /* 1st level links, hover */
    .sf-menu li a:hover {
    	color: white;
    	background-color: lime;
    }
    
    /* 1st level current page */
    .sf-menu .current_page_item a,
    .sf-menu .current_page_ancestor a,
    .sf-menu .current_page_parent a {
        border-bottom-color: white;
    	background-color: TEAL;
    }
    
    /* 1st level down triangles with pure css*/
    .sf-menu li .sf-sub-indicator {
    	text-indent:-9999px;
    	line-height: 0;
    	border-color:YELLOW transparent transparent;
    	border-style:solid;
    	border-width:4px; /*controls size of triangle */
    	display:inline-block;
    	margin-left:5px;
    }
    
    /*** 2nd level ***/
    
    /* sub menu */
    .sf-menu ul {
        border-right:1px solid;
        border-bottom:1px solid;
    	border-color: yellow;
    }
    .sf-menu li:hover ul,
    .sf-menu li.sfHover ul {
    	top:32px; /* overriding essential styles- adjust if you have gaps between first level and drop-down sub menu*/
    }
    .sf-menu ul ul {
        margin-top:0; /*unlikely to need adjusting */
    }
    
    /* 2nd level links, no hover */
    .sf-menu li li a, .sf-menu li.sfHover li a {
    	color: orange;
    	background-color: blue;
    	border-color: green;
    	border-bottom: 0;
    }
    
    /* 2nd level links, while hovering over sub menu */
    .sf-menu li li.sfHover a{
    	color: black;
    	background-color: silver;
    }
    
    /* 2nd level links, hover */
    .sf-menu li li a:hover, .sf-menu li.sfHover li a:hover {
    	color: white;
    	background-color: aqua;
    }
    
    /* 2nd level current page */
    .sf-menu li li.current_page_item a,
    .sf-menu li li.current_page_ancestor a,
    .sf-menu li li.current_page_parent a {
    	background-color: TEAL;
    }
    
    /* 2nd level side triangles with pure CSS */
    .sf-menu li li .sf-sub-indicator { /*right arrow*/
    	border-color: transparent transparent transparent WHITE;
    }
    
    /*** 3rd Level and beyond ***/
    
    /* 3rd level links, no hover */
    .sf-menu li li li a, .sf-menu li.sfHover li li a {
    	color: blue;
    	background-color: red;
    	border-color: blue;
    }
    
    /* 3rd level links, hover */
    .sf-menu li li li a:hover, .sf-menu li.sfHover li li a:hover {
    	color: white;
    	background-color: pink;
    }
    
    /* 3rd level current page */
    .sf-menu li li li.current_page_item a,
    .sf-menu li li li.current_page_ancestor a,
    .sf-menu li li li.current_page_parent a {
    	background-color: TEAL;
    }

    if you wish to use my additional top menu from this post you will also need the following style rule to clear the header. i had issues w/ the links not being clickable without this... I presume the floated menu was lying behind the header div and was therefore inaccessible.

    #header{
    	clear:both;
    }
    Posted 13 years ago #
  4. 7. Killing Dropdowns

    As a bonus, here is how you would remove the thematic dropdowns entirely if you don't need the script:
    http://themeshaper.com/guide-customizing-thematic-theme-framework/

    // Filter away the default scripts loaded with Thematic
    function childtheme_head_scripts() {
        // Abscence makes the heart grow fonder
    }
    add_filter('thematic_head_scripts','childtheme_head_scripts');

    EDIT 4/12/2012
    The above is now a bit outdated. It will still work as of today's lastest stable development release.... version 0.9.8. But in the upcoming update it is going away in favor of proper enqueuing of the header scripts. therefore i now recommend using:

    function childtheme_override_head_scripts(){
       // Abscence makes the heart grow fonder
    }

    eventually you'll be able to remove the action from its hook, but the above will work now and in the future version.

    8. Adding those sub indicator arrows

    as another bonus, you can change the superfish behavior to enable those little rightquote marks to indicate that a particular item has a submenu.

    you will need to paste this into a text file, and save it as thematic-dropdowns.js and put it in a folder of your child theme called "scripts" (no quotes)

    jQuery.noConflict();
    jQuery(document).ready(function(){
        jQuery("ul.sf-menu").supersubs({
            minWidth:    12,                                // minimum width of sub-menus in em units
            maxWidth:    27,                                // maximum width of sub-menus in em units
            extraWidth:  1                                  // extra width can ensure lines don't sometimes turn over
                                                            // due to slight rounding differences and font-family
        }).superfish({
            delay:       400,                               // delay on mouseout
            animation:   {opacity:'show',height:'show'},    // fade-in and slide-down animation
            speed:       'fast',                            // faster animation speed
            autoArrows:  true,                             // enable generation of arrow mark-up
            dropShadows: false                              // disable drop shadows
        });
    });

    then you'd put the following in your functions file

    // Dropdowns - Filter Default options
    // http://users.tpg.com.au/j_birch/plugins/superfish/#options
    function childtheme_dropdown_options($dropdown_options) {
    	$dropdown_options = '<script type="text/javascript" src="'. get_bloginfo('stylesheet_directory') .'/scripts/thematic-dropdowns.js"></script>';
    	return $dropdown_options;
    }
    
    add_filter('thematic_dropdown_options','childtheme_dropdown_options');
    Posted 13 years ago #
  5. i want your drugs :)

    Posted 13 years ago #
  6. hey johnny- his name is José... or sometimes Pepé and he goes well with lime juice

    9. Creating a totally custom menu

    for a totally custom look you can hard code the menu. this can be a good solution if you know your menu will always stay the same OR if you want to add some extra span tags and create an image based rollover menu. the best reference is still:

    http://themeshaper.com/wordpress-menu-tricks/

    a very good demo of this technique is now being used by rscamero92 at the site : http://jamiescreativecorner.com/

    the code was originally shared here: http://forums.themeshaper.com/topic/my-custom-menu

    i include it here for completeness.

    // Remove the default Thematic Access
    function remove_thematic_actions() {
        remove_action('thematic_header','thematic_access',9);
    }
    add_action('init','remove_thematic_actions');
    
    // My custom menu
    
    function custom_childtheme_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');?></div>
    	<div class="menu">
    		<ul class="menu">
    		<li class="tab tab-home"><a href="#/">Home</a></li>
    		<li class="tab tab-1"><a href="#">About</a></li>
    		<li class="tab tab-2"><a href="#">Contact</a></li>
    		<li class="tab tab-3"><a href="#">Projects</a></li>
    		<li class="tab tab-4"><a href="#">Inspire</a></li>
    		<li class="tab tab-5"><a href="#">Featured</a></li>
    		<li class="tab tab-6"><a href="#">Advertise</a></li>
    		</ul>
    	</div><!-- #menu -->
    	</div><!-- #access --> 
    
    <?php }
    
    add_action('thematic_header','custom_childtheme_access',9);


    /*EDIT Jan 7 2012
    as of 0.9.8 you no longer need to remove and then add this action, you can take advantage of the childtheme_overrides like so:

    // My custom menu
    
    function childtheme_override_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');?></div>
    	<div class="menu">
    		<ul class="menu">
    		<li class="tab tab-home"><a href="#/">Home</a></li>
    		<li class="tab tab-1"><a href="#">About</a></li>
    		<li class="tab tab-2"><a href="#">Contact</a></li>
    		<li class="tab tab-3"><a href="#">Projects</a></li>
    		<li class="tab tab-4"><a href="#">Inspire</a></li>
    		<li class="tab tab-5"><a href="#">Featured</a></li>
    		<li class="tab tab-6"><a href="#">Advertise</a></li>
    		</ul>
    	</div><!-- #menu -->
    	</div><!-- #access --> 
    
    <?php }

    */ end edit

    hopefully it is obvious that you must change the links from # to whatever is relevant for your site. also note that the ul class is "menu" and not "sf-menu" so none of the default styling is pulled in.

    another quick note: it wasn't used here, but it is possible to amend your li elements to dynamically add a 'you are here' type of page class

    <li class="<?php if ( is_page('contact') ) { ?>current_page_item<?php } else { ?>page_item<?php } ?>"><a href="<?php echo get_option('home') ?>/contact/" title="Contact Me">Contact</a></li>

    this can be extended ad nauseum w/ conditionals for page parent and page ancestor, but i'll just point you to the codex if you really need that can of customization. EDIT Jan 7 2012: unless you are doing something extreme, there is little need to hard-code the menu when you can create custom menus in WP3.0+

    http://codex.wordpress.org/Template_Tags

    and finally the css for the above example. some sprites are being used (aka the image and its hover are in 1 file). you could go all out and pull all the images into 1 file to speed up your site by reducing the number of images you have to load. see here for an example:

    http://line25.com/tutorials/how-to-create-a-css-menu-using-image-sprites

    .menu {
    margin: 0;
    }
    
    .menu li {
    display: inline;
    }
    
    .menu li a {
    text-indent: -99999px;
    float: left;
    margin-top: 15px;
    }
    
    .menu li.tab-home a {
    width: 91px;
    height: 24px;
    background: url(images/menu_02.png) no-repeat scroll 0 0;
    }
    
    .menu li.tab-home a:hover {
    background: url(images/menu_02.png) no-repeat scroll 0 -25px;
    }
    
    .menu li.tab-1 a {
    height: 24px;
    background: url(images/menu_03.png) no-repeat scroll 0 0;
    width: 105px;
    }
    
    .menu li.tab-1 a:hover {
    background: url(images/menu_03.png) no-repeat scroll 0 -25px;
    }
    
    .menu li.tab-2 a {
    width: 136px;
    height: 24px;
    background: url(images/menu_04.png) no-repeat scroll 0 0;
    }
    
    .menu li.tab-2 a:hover {
    background: url(images/menu_04.png) no-repeat scroll 0 -25px;
    }
    
    .menu li.tab-3 a {
    background: url(images/menu_05.png) no-repeat scroll 0 0;
    height: 24px;
    width: 150px;
    }
    
    .menu li.tab-3 a:hover {
    background: url(images/menu_05.png) no-repeat scroll 0 -25px;
    }
    
    .menu li.tab-4 a {
    background: url(images/menu_06.png) no-repeat scroll 0 0;
    height: 24px;
    width: 125px;
    }
    
    .menu li.tab-4 a:hover {
    background: url(images/menu_06.png) no-repeat scroll 0 -25px;
    }
    
    .menu li.tab-5 a {
    background: url(images/menu_07.png) no-repeat scroll 0 0;
    height: 24px;
    width: 155px;
    }
    
    .menu li.tab-5 a:hover {
    background: url(images/menu_07.png) no-repeat scroll 0 -25px;
    }
    
    .menu li.tab-6 a {
    background: url(images/menu_08.png) no-repeat scroll 0 0;
    width: 155px;
    height: 24px;
    }
    
    .menu li.tab-6 a:hover {
    background: url(images/menu_08.png) no-repeat scroll 0 -25px;
    }
    Posted 13 years ago #
  7. SWEET!!

    Posted 13 years ago #
  8. You are an absolute star. I'm book marking this thread as a reference, excellent stuff.

    Posted 13 years ago #
  9. Jamie Mitchell
    Member

    you rock Viking !

    Posted 13 years ago #
  10. iCristiano
    Member

    Helga, fantastic topic!

    I tryed to do what you said here:

    the following is all you need to get a single 3.0 menu to replace the default thematic #access menu.

    Enable 1 wordpress 3.0 Menu in the Thematic #access

    // change Thematic #access menu for a Wordpress 3.0 menu
    function child_access_menu() {
    $menu_sys = 'wp_nav_menu';
    return $menu_sys;
    }
    add_filter('thematic_menu_type', 'child_access_menu');

    But it didn´t work...

    I had created 2 custom menus on WP... one of then I´m using on sidebar widget. I want to replace the default Thematic menu with the other one... what should I do??

    Thanks!!!

    Posted 13 years ago #
  11. after you create the menu- you must also select it in the Theme Locations box on the Menus panel in the WP dashboard.

    Posted 13 years ago #
  12. iCristiano
    Member

    The problem is that in Menus Panel it still saying that "my theme doesn´t suport menus", so I can´t select it...

    Posted 13 years ago #
  13. iCristiano
    Member

    In fact, that was the only code I inserted on functions.php

    // change Thematic #access menu for a Wordpress 3.0 menu
    function child_access_menu() {
    $menu_sys = 'wp_nav_menu';
    return $menu_sys;
    }
    add_filter('thematic_menu_type', 'child_access_menu');

    Do I need to register the menu first??

    Posted 13 years ago #
  14. what version of thematic are you using? i am pretty sure it doesn't work w/ the 0.9.6.2 which is the version currently in the wordpress repository. you will need the latest stable dev version which was mentioned above: http://developing.thematic4you.com/thematic-development-release/

    Posted 13 years ago #
  15. iCristiano
    Member

    Perfect! That was the problem! ;)

    Posted 13 years ago #
  16. Priceless stuff here HtV! The CSS "tutorial" alone is pure gold.

    Posted 13 years ago #
  17. A W E S O M E       : )       Thanks for taking the time to contribute a kick *ss thread.

    Posted 13 years ago #
  18. Thanks Helga! Super appreciated!

    Posted 13 years ago #
  19. orionmessier42
    Member

    Can't thank you enough HtV! AWESOME thread!

    Posted 13 years ago #
  20. José... Cuervo?

    Thank you for this amazing post, I keep coming back to it

    Posted 13 years ago #
  21. yes cuervo... but more commonly his cheap cousin pépé lopez. ;) merging my experiences from my latest thread on menus to this one...

    10. Advanced Menus in Wordpress 3.0

    Turns out that WP3 has some extra menu features that are hidden by default. On the menus page, at the top-right of the screen there is "screen options". clicking on this will reveal some checkboxes that will let you toggle the options you would like to be shown for each new menu item... which include descriptions and custom classes. that's right, you can add a custom class to every single menu item from the back-end!! to use descriptions however, you must get into some more advanced stuff.

    first you must create a custom 'walker' function. idk why it is called a walker, but essentially it seems to be responsible for spitting out the HTML of the menus. for my example here I copied the one in and only added 1 line to add the description to the html.

    class Custom_Walker extends Walker_Nav_Menu {
          	/**
          	 * @see Walker::$tree_type
          	 * @since 3.0.0
          	 * @var string
          	 */
          	var $tree_type = array( 'post_type', 'taxonomy', 'custom' );
    
          	/**
          	 * @see Walker::$db_fields
          	 * @since 3.0.0
          	 * @todo Decouple this.
          	 * @var array
          	 */
          	var $db_fields = array( 'parent' => 'menu_item_parent', 'id' => 'db_id' );
    
          	/**
          	 * @see Walker::start_lvl()
          	 * @since 3.0.0
          	 *
          	 * @param string $output Passed by reference. Used to append additional content.
          	 * @param int $depth Depth of page. Used for padding.
          	 */
          	function start_lvl(&$output, $depth) {
          		$indent = str_repeat("\t", $depth);
          		$output .= "\n$indent<ul class=\"sub-menu\">\n";
          	}
    
          	/**
          	 * @see Walker::end_lvl()
          	 * @since 3.0.0
          	 *
          	 * @param string $output Passed by reference. Used to append additional content.
          	 * @param int $depth Depth of page. Used for padding.
          	 */
          	function end_lvl(&$output, $depth) {
          		$indent = str_repeat("\t", $depth);
          		$output .= "$indent</ul>\n";
          	}
    
          	/**
          	 * @see Walker::start_el()
          	 * @since 3.0.0
          	 *
          	 * @param string $output Passed by reference. Used to append additional content.
          	 * @param object $item Menu item data object.
          	 * @param int $depth Depth of menu item. Used for padding.
          	 * @param int $current_page Menu item ID.
          	 * @param object $args
          	 */
          	function start_el(&$output, $item, $depth, $args) {
          		global $wp_query;
          		$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
    
          		$class_names = $value = '';
    
          		$classes = empty( $item->classes ) ? array() : (array) $item->classes;
          		$classes[] = 'menu-item-' . $item->ID;
    
          		$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
          		$class_names = ' class="' . esc_attr( $class_names ) . '"';
    
          		$id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
          		$id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';
    
          		$output .= $indent . '<li' . $id . $value . $class_names .'>';
    
          		$attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
          		$attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
          		$attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
          		$attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
    
          		$item_output = $args->before;
          		$item_output .= '<a'. $attributes .'>';
          		$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
    
    /* here's the line i added */
    $item_output .= ! empty( $item->description ) ? '<span>' . esc_attr( $item->description ) . '</span>' : '';
          		$item_output .= '</a>';
          		$item_output .= $args->after;
    
          		$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
          	}
    
          	/**
          	 * @see Walker::end_el()
          	 * @since 3.0.0
          	 *
          	 * @param string $output Passed by reference. Used to append additional content.
          	 * @param object $item Page data object. Not used.
          	 * @param int $depth Depth of page. Not Used.
          	 */
          	function end_el(&$output, $item, $depth) {
          		$output .= "</li>\n";
          	}
          }

    now that you have a custom walker, you only need to include that parameter in the wp_nav_menu function like this:

    wp_nav_menu( array(  'walker' => new Custom_Walker, 	) );

    here is one of the only references i have seen on the subject:
    http://www.kriesi.at/archives/improve-your-wordpress-navigation-menu-output

    and this post at the WP forums is what helped me solve the problem. it has a few sample "walkers":
    http://wordpress.org/support/topic/wp_nav_menu-list-only-2nd-level-separate-submenu

    Posted 13 years ago #
  22. charles_i
    Member

    Now that I have the menu working how do I display Post Category content on a single page? If one of my menu items is 'blog' I need to create a page called 'blog' and a template for it called 'page-blog.php'. Now I have a Category and a couple of posts and I want to use only the 'blog' page to display them. Can't find where the code is to do this.

    Posted 13 years ago #
  23. you should create a new thread for whatever else you are trying to accomplish.

    Posted 13 years ago #
  24. Thanks Helgatheviking, might try this custom Walker Menu(though I haven't fixed my site up since getting hacked recently) and maybe give my entire site another overhaul.

    Posted 13 years ago #
  25. charles_i
    Member

    Thanks helgatheviking I'll do that. Just thought it was related to your menu so I posted it here.

    Posted 13 years ago #
  26. Thanks Helga... this is great stuff!

    Posted 13 years ago #
  27. handsofaten
    Member

    Thanks for all the good work, Helga. I'm using the latest version of Thematic (0.9.7.7) and have the following code (verbatim) in my child theme functions.php file:

    function moralground_menu_args($args) {
        $args = array(
            'show_home' => 'Home',
            'sort_column' => 'menu_order',
            'menu_class' => 'menu',
            'echo' => false
        );
        return $args;
    }
    add_filter('wp_page_menu_args','moralground_menu_args');

    And yet, Home does not appear in the menu. It works fine if I change the show_home option in the header-extensions.php file, on line 356.

    UPDATE: Ok, I see now that I need to set the final priority argument in the add_filter function to a number greater than 10, and have 'echo' => false for it work as expected. Fixed by changing the last line in the code above to:

    add_filter('wp_page_menu_args','moralground_menu_args', 20);
    Posted 13 years ago #
  28. Great post!

    Posted 13 years ago #
  29. I have a secondary menu going in a child theme with some backwards compatibility. For some reason the $args I’m setting for the fallback function aren’t working — in particular the “Home” link doesn’t seem to display.

    Here’s the code I have:

    // Register the new menus
    function register_child_menus() {
    	register_nav_menus(array(
    		'sidebar-menu' => __( 'Sidebar Menu' ),
    	));
    }
    add_action( 'init', 'register_child_menus' );
    
    // Child Sidebar Navigation
    function child_sidebar_nav() {
    
       if ( has_nav_menu( 'sidebar-menu' ) ) {
    		wp_nav_menu( array( 'theme_location' => 'sidebar-menu',
    			'show_home' 	=> __( 'Home', 'thematic' ),
    			'sort_column'	=> 'menu_order',
    			'depth' => '1',
    			'container_class' => 'menu',
    			'menu_class'	=> 'sf-menu',
    			'container_id'=>'sidebar-menu',
    			'fallback_cb' => 'child_sidebar_fall_back'
    		) );
    
        } else {
    		child_sidebar_fall_back();
        }
    }
    
    // Set up a fall-back menu for the sidebar just in case there are no menus to use.
    // Set the Args
    function child_sidebar_nav_args($args) {
    	$args = array(
    		'show_home' => __('Home', 'thematic'),
    		'sort_column' => 'menu_order',
    		'depth' => '1',
    		'container_class' => 'menu',
    		'echo' => FALSE
    	);
    	return $args;
    }
    
    // Fall back function
    function child_sidebar_fall_back() {
    	echo thematic_add_menuclass(wp_page_menu(child_sidebar_nav_args()));
    }
    // add_filter('wp_page_menu_args','child_sidebar_nav_args');

    What am I missing here?
    Is there a better way to do this?

    Posted 13 years ago #
  30. Hi Allan,

    I believe the problem is that a filter of wp_page_menu trumps arguments passed to that same function *and* Thematic is filtering it (probably when it shouldn't). Because of that you have to provide a filter also and queue it with priority.

    I'm going to suggest we remove the filter from thematic in the next version so for now just uncomment your add_filter and give it a priority of 20.

    -Gene

    Posted 13 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.