<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WP First Aid &#187; wp_nav_menu</title>
	<atom:link href="http://wpfirstaid.com/tag/wp_nav_menu/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpfirstaid.com</link>
	<description>It&#039;s WordPress ... anything is possible!</description>
	<lastBuildDate>Tue, 17 Jan 2012 16:47:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Extend the WordPress Menu</title>
		<link>http://wpfirstaid.com/2010/10/extend-the-wordpress-menu/</link>
		<comments>http://wpfirstaid.com/2010/10/extend-the-wordpress-menu/#comments</comments>
		<pubDate>Thu, 07 Oct 2010 16:29:08 +0000</pubDate>
		<dc:creator>The Doctor</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[add_filter]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[wp_list_categories]]></category>
		<category><![CDATA[wp_list_pages]]></category>
		<category><![CDATA[wp_nav_menu]]></category>
		<category><![CDATA[wp_nav_menu_items]]></category>
		<category><![CDATA[wp_page_menu]]></category>

		<guid isPermaLink="false">http://wpfirstaid.com/?p=823</guid>
		<description><![CDATA[Expand the wp_nav_menu() function by adding menu items to the output with the add_filter() function.]]></description>
			<content:encoded><![CDATA[<p>I have written <a href="http://wpfirstaid.com/tag/wp_nav_menu/">several posts</a> regarding the use of the <em>wp_nav_menu()</em> function. I have written about its uses, its implementation, and even an <a href="http://wp.me/pIDVu-6K">older post</a> regarding (some of) the <abbr title="Cascading Style Sheet">CSS</abbr> classes it generates. This post continues with an idea for extending the <em>wp_nav_menu()</em> function by adding additional items to the menu list with code versus the user interface found in the Administration Panels, such as automagically adding a self-propagating list of categories.</p>
<p>This idea is not necessarily new but finding an example may be a bit more difficult. Let&#8217;s have a look &#8230;</p>
<p>First off, there are several sources of information regarding <em>wp_nav_menu()</em> to take into consideration:</p>
<ul>
<h5><em>Each of these links will open in a new tab/window for convenience purposes.</em></h5>
<li>The <a target="_blank" href="http://codex.wordpress.org/Function_Reference/wp_nav_menu">WordPress codex</a> reference.</li>
<li>The &#8220;<a target="_blank" href="http://core.trac.wordpress.org/browser/branches/3.0/wp-includes/nav-menu-template.php#L111">core.trac.wordpress.org</a>&#8221; reference.</li>
<li>This web site&#8217;s <a target="_blank" href="http://wpfirstaid.com/tag/wp_nav_menu/">references</a>.</li>
</ul>
<p>Now that we have a list of reading material we should actually take a look at it &#8230;</p>
<ul>
<li>The first reference leads to the WordPress codex and provides the standard parameters that can be used with <em>wp_nav_menu()</em>.</li>
<li>The next reference and the experience that was offered by <a href="http://iandanielstewart.com/">Ian Stewart</a> from <a href="http://themeshaper.com/">ThemeShaper.com</a> is the real key to solving this little puzzle.</li>
<li>The last reference simply leads to the <em>wp_nav_menu()</em> tag archive here.</li>
</ul>
<p>I would suggest at least having a quick look at those pages before carrying on to the next page, especially the one referencing the <em>wp_nav_menu()</em> function in the &#8220;core&#8221;, or primary code base of WordPress, as you will find a very relevant comment there.</p>
<p>Let&#8217;s start by focusing on the following code snippet as found in the &#8220;<a href="http://core.trac.wordpress.org/browser/branches/3.0/wp-includes/nav-menu-template.php#L221">core</a>&#8221; reference:</p>
<pre class="brush: php; first-line: 221; title: ; notranslate">
// Allow plugins to hook into the menu to add their own &lt;li&gt;'s
$items = apply_filters( 'wp_nav_menu_items', $items, $args );
$items = apply_filters( &quot;wp_nav_menu_{$menu-&gt;slug}_items&quot;, $items, $args );
$nav_menu .= $items;
</pre>
<p>The beauty of this little snippet is it shows, with the use of the <em>wp_nav_menu_item</em> filter, you can add specific items to the menu output if the end-user has chosen to create a custom menu. Let&#8217;s look at an example that will allow you to add a &#8220;Home&#8221; page link to the beginning of the menu.</p>
<p>If you add the following to your &#8216;functions.php&#8217; template file it will add a home link to your <em>wp_nav_menu()</em> output:</p>
<pre class="brush: php; title: ; notranslate">
// Filter wp_nav_menu() to add additional links and other output
function new_nav_menu_items($items) {
	$homelink = '&lt;li class=&quot;home&quot;&gt;&lt;a href=&quot;' . home_url( '/' ) . '&quot;&gt;' . __('Home') . '&lt;/a&gt;&lt;/li&gt;';
	$items = $homelink . $items;
	return $items;
}
add_filter( 'wp_nav_menu_items', 'new_nav_menu_items' );
</pre>
<p>The basic premise of the function is:</p>
<ol>
<li>Assign your desired output to a variable</li>
<li>Concatenate the output variable with the <em>$items</em> variable</li>
<li>Return the $items variable so it can be used in the filter</li>
<li>Add the results of the function to <em>wp_nav_menu_items</em> with an <em><a href="http://codex.wordpress.org/Function_Reference/add_filter">add_filter()</a></em> function</li>
</ol>
<div class="nota-bene">NB: It is also important to realize that this function will work as is when a custom menu is being used, but you can easily adjust the above code to take into consideration common <em>fallback</em> functions such as <em><a href="http://codex.wordpress.org/Function_Reference/wp_list_pages">wp_list_pages()</a></em> and <em><a href="http://codex.wordpress.org/Function_Reference/wp_page_menu">wp_page_menu()</a></em>.</div>
<p>If you wish to use this when a custom menu is not being used just add the following (or similar) filter after the above code:</p>
<pre class="brush: php; title: ; notranslate">
add_filter( 'wp_list_pages', 'new_nav_menu_items' );
</pre>
<p>But what if we wanted to add something to the end of the menu output, such as a <abbr title="Really Simple Syndication">RSS</abbr> feed link, or maybe just some random text or a static URL link. Let&#8217;s look at the following example which expands upon the code above to do just that.</p>
<pre class="brush: php; title: ; notranslate">
// Filter wp_nav_menu() to add additional links and other output
function new_nav_menu_items($items) {
	$homelink = '&lt;li class=&quot;home&quot;&gt;&lt;a href=&quot;' . home_url( '/' ) . '&quot;&gt;' . __('Home') . '&lt;/a&gt;&lt;/li&gt;';
	$feedlink = '&lt;li class=&quot;feed&quot;&gt;&lt;a href=&quot;' . get_bloginfo_rss('rss2_url') . '&quot;&gt;' . __('RSS') . '&lt;/a&gt;&lt;/li&gt;';
	$random_text = '&lt;li class=&quot;rainbows&quot;&gt;&lt;a href=&quot;#&quot;&gt;OMG ... Double Rainbows!&lt;/a&gt;&lt;/li&gt;';
	$items = $homelink . $items;
	$items = $items . $feedlink;
	$items = $items . $random_text;
	return $items;
}
add_filter( 'wp_list_pages', 'new_nav_menu_items' );
add_filter( 'wp_nav_menu_items', 'new_nav_menu_items' );
</pre>
<p>There always seems to be some new way to add more uses to the core functions in <a href="http://wordpress.org/">WordPress</a> and I like to find, explore and write about them. I often implement them in the First Aid Theme, as I have done by using the above example code to add a &#8220;Home&#8221; link to the menu. On the next page I will leave you with one more example, the one I referred to in the opening paragraph.</p>
<p>Although this was a bit more involved it really did not make that much of a difference in the case of implementing this in a custom menu so without further ado here is the code snippet:</p>
<pre class="brush: php; title: ; notranslate">
function new_nav_menu_items($items) {
  $cat_menu_list = wp_list_categories( 'echo=0&amp;title_li=&amp;child_of=124' );
  $items = $items . $cat_menu_list;
  return $items;
}
add_filter( 'wp_nav_menu_items', 'new_nav_menu_items' );
</pre>
<div class="nota-bene">NB: Note with this example the reference to the parameter <em>&#8216;child_of=124&#8242;</em> &#8230; this is making use of some category hierarchical trickery; essentially you create a &#8220;phantom&#8221; category (note its ID to be used as the <em>&#8216;child_of&#8217;</em> value) to be the parent of the categories you want to display in your list. If, for example, you want all your categories to be listed and you do not use the &#8220;uncategorized&#8221; category then simply make all of your current &#8220;parent&#8221; categories children of the &#8220;uncategorized&#8221; category and change the code above to use <em>&#8216;child_of=1&#8242;</em>.</div>
<p>If you are trying this at home <strong>make back-ups</strong> of your files, just in case you want to revert your edits. Your category list hierarchy may need to be noted as well.</p>
<p>The key to this snippet is the <em><a href="http://codex.wordpress.org/Template_Tags/wp_list_categories">wp_list_categories()</a></em> by default will echo its results to the screen, you will have to set the parameter <em>&#8216;echo=0&#8242;</em> to turn off this default behavior.</p>
<p>As for using this technique for categories with a non-custom menu I will leave that as an exercise for those looking for a challenge &#8230; Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://wpfirstaid.com/2010/10/extend-the-wordpress-menu/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>An Implementation of wp_nav_menu</title>
		<link>http://wpfirstaid.com/2010/09/implement-wp_nav_menu/</link>
		<comments>http://wpfirstaid.com/2010/09/implement-wp_nav_menu/#comments</comments>
		<pubDate>Mon, 13 Sep 2010 01:49:48 +0000</pubDate>
		<dc:creator>The Doctor</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[register_nav_menu]]></category>
		<category><![CDATA[wp_list_pages]]></category>
		<category><![CDATA[wp_nav_menu]]></category>

		<guid isPermaLink="false">http://wpfirstaid.com/?p=716</guid>
		<description><![CDATA[This article will show how to implement the wp_nav_menu() function using the wp_list_pages() function as a fallback.]]></description>
			<content:encoded><![CDATA[<p>Please note, this might be considered a &#8220;Go Big, or Go Home&#8221; exercise. Please read this entire post before attempting this at home, or on your own site or theme.</p>
<p>This article will be covering the implementation of the <em>wp_nav_menu()</em> function using the <em>wp_list_pages()</em> function as a fallback. The menu will also be centered and support full drop down sub-menu items, or child pages as some would refer to them &#8230; and, the menu system now live on this site, too.</p>
<p>The following code will also be released in the free <a href="http://wordpress.org/">WordPress</a> Theme <a href="http://buynowshop.com/themes/shades/">Shades</a> at version 1.6, and it will also be the basis for the examples used in this post.</p>
<p>Let&#8217;s get started &#8230;</p>
<h3>What We Need</h3>
<ul>
<li><a href="http://codex.wordpress.org/Function_Reference/wp_list_pages">wp_list_pages()</a></li>
<li><a href="http://codex.wordpress.org/Function_Reference/wp_nav_menu">wp_nav_menu()</a></li>
<li><a href="http://codex.wordpress.org/Function_Reference/register_nav_menu">register_nav_menu()</a></li>
<li><a href="http://wp.me/pIDVu-9q">Upgrade wp_list_pages() to wp_nav_menu()</a></li>
<li><a href="http://wordpress.org/extend/themes/shades">Shades</a></li>
<li><a href="http://matthewjamestaylor.com/blog/centered-dropdown-menus">CSS</a></li>
</ul>
<p>Have a look at the codex pages above for <em><a href="http://codex.wordpress.org/Function_Reference/wp_list_pages">wp_list_pages()</a></em>, <em><a href="http://codex.wordpress.org/Function_Reference/wp_nav_menu">wp_nav_menu</a></em>, and <em><a href="http://codex.wordpress.org/Function_Reference/register_nav_menu">register_nav_menu</a></em> to get (more) familiar with the basics of these functions. As this has to do with the use of <em>wp_list_pages()</em> reading the article &#8220;<a href="http://wp.me/pIDVu-9q">Upgrade wp_list_pages() to wp_nav_menu()</a>&#8221; may also prove useful.</p>
<p>Although not absolutely necessary, getting a copy of the <a href="http://wordpress.org/extend/themes/shades">Shades</a> theme may be handy if you wish to look at the code directly rather than the examples and snippets to follow.</p>
<p>The last part is the CSS to make it all work. This is from a great article written by <a href="http://matthewjamestaylor.com/">Matthew James Taylor</a> and can be found <a href="http://matthewjamestaylor.com/blog/centered-dropdown-menus">here</a>.</p>
<p>On the next page we will look at what to do &#8230;</p>
<h3>What We Will Do</h3>
<p>First we are going to open the functions.php template file and start with adding the following code:</p>
<pre class="brush: php; first-line: 99; title: ; notranslate">
wp_nav_menu( array(
   'theme_location' =&gt; 'top-menu',
   'fallback_cb' =&gt; 'custom_list_pages'
   ) );
</pre>
<p>Next we will need to incorporate the fallback menu code via wp_list_pages(), with the following:</p>
<pre class="brush: php; first-line: 107; title: ; notranslate">
function custom_list_pages() {
  if ( is_home() || is_front_page() ) { ?&gt;
    &lt;ul&gt;&lt;?php wp_list_pages( 'title_li=' ); ?&gt;&lt;/ul&gt;
  &lt;?php } else { ?&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;&lt;?php bloginfo( 'url' ); ?&gt;&quot;&gt;&lt;?php _e( 'Home' ); ?&gt;&lt;/a&gt;&lt;/li&gt;
      &lt;?php wp_list_pages( 'title_li=' ); ?&gt;
    &lt;/ul&gt;
  &lt;?php }
}
</pre>
<p>Both of these functions will need to be included in the custom function that will be the base of our new menu system. The code looks like this:</p>
<pre class="brush: php; first-line: 97; title: ; notranslate">
function custom_nav_menu() {
    if ( function_exists( 'wp_nav_menu' ) )
      wp_nav_menu( array(
			   'theme_location' =&gt; 'top-menu',
			   'fallback_cb' =&gt; 'custom_list_pages'
			   ) );
    else
      custom_list_pages();
}
</pre>
<p>Then we need to register the custom function and give it a place to live. This code will accomplish that:</p>
<pre class="brush: php; first-line: 118; title: ; notranslate">
add_action( 'init', 'register_custom_menu' );
function register_custom_menu() {
    register_nav_menu( 'top-menu', __( 'Top Menu' ) );
}
</pre>
<p>The heavy lifting is done, now we need to address the actual display of the menu. Let&#8217;s open the header.php template file and place the custom function appropriately.</p>
<pre class="brush: php; first-line: 34; title: ; notranslate">
&lt;div id=&quot;centeredmenu&quot;&gt;
	&lt;?php custom_nav_menu(); ?&gt;
&lt;/div&gt; &lt;!-- #centeredmenu --&gt;
</pre>
<p>Now for all intent and purpose the CSS from Matthew James Taylor&#8217;s post can be dropped into the style.css file, like so:</p>
<pre class="brush: css; first-line: 202; title: ; notranslate">
/* Main menu settings */
#centeredmenu {
   clear:both;
   float:left;
   margin:0;
   padding:0;
   border-bottom:1px solid #000; /* black line below menu */
   width:100%;
   font-family:Verdana, Geneva, sans-serif; /* Menu font */
   font-size:90%; /* Menu text size */
   z-index:1000; /* This makes the dropdown menus appear above the page content below */
   position:relative;
}

/* Top menu items */
#centeredmenu ul {
   margin:0;
   padding:0;
   list-style:none;
   float:right;
   position:relative;
   right:50%;
}
#centeredmenu ul li {
   margin:0 0 0 1px;
   padding:0;
   float:left;
   position:relative;
   left:50%;
   top:1px;
}
#centeredmenu ul li a {
   display:block;
   margin:0;
   padding:.6em .5em .4em;
   font-size:1em;
   line-height:1em;
   background:#ddd;
   text-decoration:none;
   color:#444;
   font-weight:bold;
   border-bottom:1px solid #000;
}
#centeredmenu ul li.active a {
   color:#fff;
   background:#000;
}
#centeredmenu ul li a:hover {
   background:#36f; /* Top menu items background colour */
   color:#fff;
   border-bottom:1px solid #03f;
}
#centeredmenu ul li:hover a,
#centeredmenu ul li.hover a { /* This line is required for IE 6 and below */
   background:#36f; /* Top menu items background colour */
   color:#fff;
   border-bottom:1px solid #03f;
}

/* Submenu items */
#centeredmenu ul ul {
   display:none; /* Sub menus are hiden by default */
   position:absolute;
   top:2em;
   left:0;
   right:auto; /*resets the right:50% on the parent ul */
   width:10em; /* width of the drop-down menus */
}
#centeredmenu ul ul li {
   left:auto;  /*resets the left:50% on the parent li */
   margin:0; /* Reset the 1px margin from the top menu */
   clear:left;
   width:100%;
}
#centeredmenu ul ul li a,
#centeredmenu ul li.active li a,
#centeredmenu ul li:hover ul li a,
#centeredmenu ul li.hover ul li a { /* This line is required for IE 6 and below */
   font-size:.8em;
   font-weight:normal; /* resets the bold set for the top level menu items */
   background:#eee;
   color:#444;
   line-height:1.4em; /* overwrite line-height value from top menu */
   border-bottom:1px solid #ddd; /* sub menu item horizontal lines */
}
#centeredmenu ul ul li a:hover,
#centeredmenu ul li.active ul li a:hover,
#centeredmenu ul li:hover ul li a:hover,
#centeredmenu ul li.hover ul li a:hover { /* This line is required for IE 6 and below */
   background:#36f; /* Sub menu items background colour */
   color:#fff;
}

/* Flip the last submenu so it stays within the page */
#centeredmenu ul ul.last {
   left:auto; /* reset left:0; value */
   right:0; /* Set right value instead */
}

/* Make the sub menus appear on hover */
#centeredmenu ul li:hover ul,
#centeredmenu ul li.hover ul { /* This line is required for IE 6 and below */
   display:block; /* Show the sub menus */
}
</pre>
<p>Although this will work as is in most cases there are a few items that can be modified to better suit a theme. On the next page is the actual CSS being used in the <a href="http://buynowshop.com/themes/shades/">Shades</a> theme, version 1.6, to accommodate its requirements as well as meeting current theme review criteria as noted on the WordPress codex page <a href="http://codex.wordpress.org/Theme_Review">here</a>.</p>
<h3>What May Need To Be Adjusted</h3>
<p>Note the changes at the following lines: 231, 251, 254, 259, 262, 296, and especially 310 for multiple line menus.</p>
<pre class="brush: css; first-line: 202; highlight: [231,251,254,259,262,296,310]; title: ; notranslate">
/* Main menu settings */
#centeredmenu {
   clear:both;
   float:left;
   margin:0;
   padding:0;
   border-bottom:1px solid #000; /* black line below menu */
   width:100%;
   font-family:Verdana, Geneva, sans-serif; /* Menu font */
   font-size:90%; /* Menu text size */
   z-index:1000; /* This makes the dropdown menus appear above the page content below */
   position:relative;
}

/* Top menu items */
#centeredmenu ul {
   margin:0;
   padding:0;
   list-style:none;
   float:right;
   position:relative;
   right:50%;
}
#centeredmenu ul li {
   margin:0 0 0 1px;
   padding:0;
   float:left;
   position:relative;
   left:50%;
   /* top:1px; */
}
#centeredmenu ul li a {
   display:block;
   margin:0;
   padding:.6em .5em .4em;
   font-size:1em;
   line-height:1em;
   background:#ddd;
   text-decoration:none;
   color:#444;
   font-weight:bold;
   border-bottom:1px solid #000;
}
#centeredmenu ul li.active a {
   color:#fff;
   background:#000;
}
#centeredmenu ul li a:hover {
   /* background:#36f; /* Top menu items background colour */
   background: #8c8c8c;
   color:#fff;
   /* border-bottom:1px solid #03f; */
   border-bottom:1px solid #444;
}
#centeredmenu ul li:hover a,
#centeredmenu ul li.hover a { /* This line is required for IE 6 and below */
   /* background:#36f; /* Top menu items background colour */
   background: #8c8c8c;
   color:#fff;
   /* border-bottom:1px solid #03f; */
   border-bottom:1px solid #444;
}

/* Submenu items */
#centeredmenu ul ul {
   display:none; /* Sub menus are hiden by default */
   position:absolute;
   top:2em;
   left:0;
   right:auto; /*resets the right:50% on the parent ul */
   width:10em; /* width of the drop-down menus */
}
#centeredmenu ul ul li {
   left:auto;  /*resets the left:50% on the parent li */
   margin:0; /* Reset the 1px margin from the top menu */
   clear:left;
   width:100%;
}
#centeredmenu ul ul li a,
#centeredmenu ul li.active li a,
#centeredmenu ul li:hover ul li a,
#centeredmenu ul li.hover ul li a { /* This line is required for IE 6 and below */
   font-size:.8em;
   font-weight:normal; /* resets the bold set for the top level menu items */
   background:#eee;
   color:#444;
   line-height:1.4em; /* overwrite line-height value from top menu */
   border-bottom:1px solid #ddd; /* sub menu item horizontal lines */
}
#centeredmenu ul ul li a:hover,
#centeredmenu ul li.active ul li a:hover,
#centeredmenu ul li:hover ul li a:hover,
#centeredmenu ul li.hover ul li a:hover { /* This line is required for IE 6 and below */
   /* background:#36f; /* Sub menu items background colour */
   background: #8c8c8c;
   color:#fff;
}

/* Flip the last submenu so it stays within the page */
#centeredmenu ul ul.last {
   left:auto; /* reset left:0; value */
   right:0; /* Set right value instead */
}

/* Make the sub menus appear on hover */
#centeredmenu ul li:hover ul,
#centeredmenu ul li.hover ul { /* This line is required for IE 6 and below */
   display:block; /* Show the sub menus */
   z-index: 1500; /* Required for multi-line menus */
}

/* -- Extra Window Dressings -- */
#centeredmenu ul li a {
  /* optional rounded corners for browsers that support it */
  -moz-border-radius: 5px 5px 0 0;
  -khtml-border-radius: 5px 5px 0 0;
  -webkit-border-radius: 5px 5px 0 0;
  border-radius: 5px 5px 0 0;
}

#centeredmenu ul li:first-child a { /* First parent menu item */
  /* optional rounded corners for browsers that support it */
  -moz-border-radius: 10px 5px 0 0;
  -khtml-border-radius: 10px 5px 0 0;
  -webkit-border-radius: 10px 5px 0 0;
  border-radius: 10px 5px 0 0;
}

#centeredmenu ul li:last-child a { /* Last parent menu item */
  /* optional rounded corners for browsers that support it */
  -moz-border-radius: 5px 10px 0 0;
  -khtml-border-radius: 5px 10px 0 0;
  -webkit-border-radius: 5px 10px 0 0;
  border-radius: 5px 10px 0 0;
}

#centeredmenu ul ul li:last-child a { /* remove rounded corners from sub-menu items */
  /* optional rounded corners for browsers that support it */
  -moz-border-radius: 0;
  -khtml-border-radius: 0;
  -webkit-border-radius: 0;
  border-radius: 0;
}

#centeredmenu ul ul ul li a { /* &quot;grandchild&quot; sub-menu items */
  padding-left: 10px;
}
</pre>
<p>A little extra was added at the end of the CSS to add some rounded corner emphasis to the top menu tabs as well as some additional padding for sub-sub-menu items.</p>
<p>Thanks again to <a href="http://matthewjamestaylor.com/about">Mathew James Taylor</a> for the great CSS.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://wpfirstaid.com/2010/09/implement-wp_nav_menu/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Upgrade wp_list_categories() to wp_nav_menu()</title>
		<link>http://wpfirstaid.com/2010/07/upgrade-wp_list_categories-to-wp_nav_menu/</link>
		<comments>http://wpfirstaid.com/2010/07/upgrade-wp_list_categories-to-wp_nav_menu/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 13:39:07 +0000</pubDate>
		<dc:creator>The Doctor</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[wp_list_categories]]></category>
		<category><![CDATA[wp_nav_menu]]></category>

		<guid isPermaLink="false">http://wpfirstaid.com/?p=659</guid>
		<description><![CDATA[In this third installment in the upgrade to wp_nav_menu() series of posts, I will be dealing with moving from wp_list_categories() to wp_nav_menu(). Let&#8217;s start with the same basic outline and list the default options for each function. We will start with wp_nav_menu() 1 first: We follow with wp_list_categories() 2, 3 which is often wrapped in [...]]]></description>
			<content:encoded><![CDATA[<p>In this third installment in the upgrade to <em>wp_nav_menu()</em> series of posts, I will be dealing with moving from <em>wp_list_categories()</em> to <em>wp_nav_menu()</em>.</p>
<p>Let&#8217;s start with the same basic outline and list the default options for each function. We will start with <em>wp_nav_menu()</em><sup> 1</sup> first:</p>
<pre class="brush: php; title: ; notranslate">
wp_nav_menu( array(
    'menu'              =&gt; '',
    'container'         =&gt; 'div',
    'container_class'   =&gt; '',
    'container_id'      =&gt; '',
    'menu_class'        =&gt; 'menu',
    'menu_id'           =&gt; '',
    'echo'              =&gt; true,
    'fallback_cb'       =&gt; 'wp_page_menu',
    'before'            =&gt; '',
    'after'             =&gt; '',
    'link_before'       =&gt; '',
    'link_after'        =&gt; '',
    'depth'             =&gt; 0,
    'walker'            =&gt; '',
    'theme_location'    =&gt; ''
    ) );
</pre>
<p>We follow with <em>wp_list_categories()</em><sup> 2, 3</sup> which is often wrapped in a &lt;ul class=&#8221;menu&#8221;&gt; tag:</p>
<pre class="brush: php; title: ; notranslate">
&lt;ul class=&quot;menu&quot;&gt;
wp_list_categories( array(
    'include'           =&gt; '',
    'exclude'           =&gt; '',
    'exclude_tree'      =&gt; '',
    'child_of'          =&gt; 0,
    'hide_empty'        =&gt; 1,
    'orderby'           =&gt; 'name',
    'order'             =&gt; 'ASC',
    'use_desc_for_title'=&gt; 1,
    'number'            =&gt; NULL,
    'hierarchical'      =&gt; true,
    'show_count'        =&gt; 0,
    'pad_counts'        =&gt; 0,
    'style'             =&gt; 'list',
    /* 'style' set to list &quot;creates list items for an unordered list&quot; */
    'show_option_all'   =&gt; '',
    'show_option_none'  =&gt; __('No categories'),
    'show_last_update'  =&gt; 0,
    'feed'              =&gt; '',
    'feed_type'         =&gt; '',
    'feed_image'        =&gt; '',
    'current_category'  =&gt; 0,
    'taxonomy'          =&gt; 'category',
    'title_li'          =&gt; __( '' ),
    /* 'title_li' set to '' for menus from the default 'Categories' */
    'echo'              =&gt; 1,
    'depth'             =&gt; 0,
    'walker'            =&gt; 'Walker_Category'
    ) );
&lt;/ul&gt;
</pre>
<p>Here is the break-down of the <em>wp_list_categories()</em> default options from above:</p>
<ul>
<li><code>'include'</code> &#8211; not used</li>
<li><code>'exclude'</code> &#8211; not used</li>
<li><code>'exclude_tree'</code> &#8211; not used</li>
<li><code>'child_of'</code> &#8211; not used</li>
<li><code>'hide_empty'</code> &#8211; not used</li>
<li><code>'orderby'</code> &#8211; not used</li>
<li><code>'order'</code> &#8211; not used</li>
<li><code>'use_desc_for_title'</code> &#8211; not used</li>
<li><code>'number'</code> &#8211; not used</li>
<li><code>'hierarchical'</code> &#8211; not used</li>
<li><code>'show_count'</code> &#8211; not used</li>
<li><code>'pad_counts'</code> &#8211; not used</li>
<li><code>'style'</code> &#8211; not used</li>
<li><code>'show_option_all'</code> &#8211; not available</li>
<li><code>'show_option_none'</code> &#8211; not available</li>
<li><code>'show_last_update'</code> &#8211; not available</li>
<li><code>'feed'</code> &#8211; not available</li>
<li><code>'feed_type'</code> &#8211; not available</li>
<li><code>'feed_image'</code> &#8211; not available</li>
<li><code>'current_category'</code> &#8211; not available</li>
<li><code>'taxonomy'</code> &#8211; not available</li>
<li><code>'title_li'</code> &#8211; not used</li>
<li><code>'echo'</code> – similar to wp_nav_menu(); true versus 1 as value</li>
<li><code>'depth'</code> – same as wp_nav_menu()</li>
<li><code>'walker'</code> &#8211; see below for additional notes</li>
</ul>
<p>Although there are great many options available to be used with <em>wp_list_categoires()</em> most are not used (as noted in the list above) in place of the user interface of <em>wp_nav_menu()</em> found under Appearance | Menu in the dashboard. The options that are marked as &#8220;not available&#8221; are currently not directly supported by <em>wp_nav_menu()</em> without the application of filters. The last few options remaining match up almost exactly with <em>wp_page_nav()</em> in a similar fashion as was shown with <em>wp_list_pages()</em>.</p>
<p>Just like the <em>wp_list_pages()</em> consideration, the <em>wp_nav_menu()</em> fallback_cb option may be set to <code>'fallback_cb' => 'wp_list_categories'</code>. This backward compatibility may also be addressed with a custom function as was noted, too.</p>
<p>Note: In most cases you would leave the <em>wp_nav_menu()</em> <code>'walker'</code> option set to its default <code>NULL</code> although <em>wp_list_categories()</em> uses its own default walker class.</p>
<div class="footnote">
<ol>Resources:</p>
<li><a href="http://core.trac.wordpress.org/browser/trunk/wp-includes/nav-menu-template.php">../wp-includes/nav-menu-template.php</a></li>
<li><a href="http://core.trac.wordpress.org/browser/trunk/wp-includes/category-template.php">../wp-includes/category-template.php</a></li>
<li><a href="http://codex.wordpress.org/Template_Tags/wp_list_categories">Template Tags/wp list categories</a></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://wpfirstaid.com/2010/07/upgrade-wp_list_categories-to-wp_nav_menu/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Upgrade wp_list_pages() to wp_nav_menu()</title>
		<link>http://wpfirstaid.com/2010/07/upgrade-wp_list_pages-to-wp_nav_menu/</link>
		<comments>http://wpfirstaid.com/2010/07/upgrade-wp_list_pages-to-wp_nav_menu/#comments</comments>
		<pubDate>Sat, 17 Jul 2010 01:35:34 +0000</pubDate>
		<dc:creator>The Doctor</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[wp_list_pages]]></category>
		<category><![CDATA[wp_nav_menu]]></category>

		<guid isPermaLink="false">http://wpfirstaid.com/?p=584</guid>
		<description><![CDATA[A few options to address and with possibly a minor edit to the theme, you can upgrade wp_list_pages() easily to wp_nav_menu() in your theme.]]></description>
			<content:encoded><![CDATA[<p>Following in the series dealing with <a href="http://wpfirstaid.com/2010/07/upgrade-wp_page_menu-to-wp_nav_menu/">upgrading to the <em>wp_nav_menu()</em></a> function in <a href="http://wordpress.org">WordPress</a> 3.0 from menus derived from the template tags: <a href="http://codex.wordpress.org/Function_Reference/wp_page_menu"><em>wp_page_menu()</em></a>; <a href="http://codex.wordpress.org/Function_Reference/wp_list_pages"><em>wp_list_pages()</em></a>; and, <a href="http://codex.wordpress.org/Template_Tags/wp_list_categories"><em>wp_list_categories()</em></a>. This post will be covering the options involved in updating to <em>wp_nav_menu()</em> from <em>wp_list_pages()</em>.</p>
<p>Like the last post in the series we will look at the default arguments used by each function, starting with <em>wp_nav_menu()</em><sup> 1</sup>:</p>
<pre class="brush: php; title: ; notranslate">
wp_nav_menu( array(
    'menu'              =&gt; '',
    'container'         =&gt; 'div',
    'container_class'   =&gt; '',
    'container_id'      =&gt; '',
    'menu_class'        =&gt; 'menu',
    'menu_id'           =&gt; '',
    'echo'              =&gt; true,
    'fallback_cb'       =&gt; 'wp_page_menu',
    'before'            =&gt; '',
    'after'             =&gt; '',
    'link_before'       =&gt; '',
    'link_after'        =&gt; '',
    'depth'             =&gt; 0,
    'walker'            =&gt; '',
    'theme_location'    =&gt; ''
    ) );
</pre>
<p>The following is a default &#8220;menu&#8221; version of <em>wp_list_pages()</em><sup> 2, 3</sup>, often wrapped within a &lt;ul class=&#8221;menu&#8221;&gt; tag:</p>
<pre class="brush: php; title: ; notranslate">
&lt;ul class=&quot;menu&quot;&gt;
&lt;?php wp_list_pages( array(
    'sort_column'       =&gt; 'menu_order, post_title',
    'include'           =&gt; '',
    'exclude'           =&gt; '',
    'exclude_tree'      =&gt; '',
    'child_of'          =&gt; 0,
    'show_date'         =&gt; '',
    'date_format'       =&gt; get_option('date_format'),
    'title_li'          =&gt; __(''),
    /* 'title_li' set to '' for menus from the default 'Pages' */
    'authors'           =&gt; '',
    'echo'              =&gt; 1,
    'link_before'       =&gt; '',
    'link_after'        =&gt; '',
    'depth'             =&gt; 0,
    'walker'            =&gt; ''
    ) ); ?&gt;
&lt;/ul&gt;
</pre>
<p>Here is the break-down of the <em>wp_list_pages()</em> default options from above:</p>
<ul>
<li><code>'sort_column'</code> &#8211; not used</li>
<li><code>'include'</code> &#8211; not used</li>
<li><code>'exclude'</code> &#8211; not used</li>
<li><code>'exclude_tree'</code> &#8211; not used</li>
<li><code>'child_of'</code> &#8211; not used</li>
<li><code>'show_date'</code> &#8211; not used</li>
<li><code>'date_format'</code> &#8211; not used</li>
<li><code>'title_li'</code> &#8211; not used, see below for additional notes</li>
<li><code>'authors'</code> &#8211; not used</li>
<li><code>'echo'</code> &#8211; similar to wp_nav_menu(); true versus 1 as value</li>
<li><code>'link_before'</code> &#8211; same as wp_nav_menu()</li>
<li><code>'link_after'</code> &#8211; same as wp_nav_menu()</li>
<li><code>'depth'</code> &#8211; same as wp_nav_menu()</li>
<li><code>'walker'</code> &#8211; same as wp_nav_menu()</li>
</ul>
<p>Similar to <em>wp_page_menu()</em>, the &#8216;sort_column&#8217;, &#8216;include&#8217;, &#8216;exclude&#8217;, &#8216;exclude_tree&#8217;, and &#8216;child_of&#8217; are replaced via the end-user&#8217;s specific choices. The &#8216;show_date&#8217; and its related &#8216;date_format&#8217; option, as well as the &#8216;author&#8217; argument, are not available within the default <em>wp_nav_menu()</em> structure. Once again, the balance of the default options in <em>wp_list_pages()</em> matches the defaults found in <em>wp_nav_menu()</em>.</p>
<p>Also consider setting the <em>wp_nav_menu()</em> fallback_cb option to <code>'fallback_cb' => 'wp_list_pages'</code>. This backward compatibility may also be addressed with a custom function as <a href="http://www.nkuttler.de/2010/06/08/wp_nav_menu-wordpress-3-0/">posted by Nicolas Kuttler</a>.</p>
<p>Note: If the <code>'title_li' => __('')</code> option was being used it may also require the removal of the wrapping &lt;ul&gt; tag in the existing menu structure created with <em>wp_list_pages()</em>.</p>
<div class="footnote">
<ol>Resources:</p>
<li><a href="http://core.trac.wordpress.org/browser/trunk/wp-includes/nav-menu-template.php">../wp-includes/nav-menu-template.php</a></li>
<li><a href="http://core.trac.wordpress.org/browser/trunk/wp-includes/post-template.php">../wp-includes/post-template.php</a></li>
<li><a href="http://codex.wordpress.org/Function_Reference/wp_list_pages">Function Reference/wp list pages</a></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://wpfirstaid.com/2010/07/upgrade-wp_list_pages-to-wp_nav_menu/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Upgrade wp_page_menu() to wp_nav_menu()</title>
		<link>http://wpfirstaid.com/2010/07/upgrade-wp_page_menu-to-wp_nav_menu/</link>
		<comments>http://wpfirstaid.com/2010/07/upgrade-wp_page_menu-to-wp_nav_menu/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 23:46:26 +0000</pubDate>
		<dc:creator>The Doctor</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[wp_nav_menu]]></category>
		<category><![CDATA[wp_page_menu]]></category>

		<guid isPermaLink="false">http://wpfirstaid.com/?p=552</guid>
		<description><![CDATA[Upgrading from wp_page_menu() to wp_nav_menu() may be as easy as a simple find and replace operation.]]></description>
			<content:encoded><![CDATA[<p>WordPress version 3.0 has been live for a while and a lot of people want to make use of the <a href="http://codex.wordpress.org/Function_Reference/wp_nav_menu"><em>wp_nav_menu()</em></a> functionality but they are using one of the older template tags: <a href="http://codex.wordpress.org/Function_Reference/wp_page_menu"><em>wp_page_menu()</em></a>; <a href="http://codex.wordpress.org/Function_Reference/wp_list_pages"><em>wp_list_pages()</em></a>; or, <a href="http://codex.wordpress.org/Template_Tags/wp_list_categories"><em>wp_list_categories()</em></a>.</p>
<p>This post will be dealing with function arguments in common between <em>wp_nav_menu()</em> and <em>wp_page_menu()</em>. Follow-up posts will be covering <a href="http://wpfirstaid.com/2010/07/upgrade-wp_list_pages-to-wp_nav_menu/"><em>wp_list_pages()</em></a> and <a href="http://wpfirstaid.com/2010/07/upgrade-wp_list_categories-to-wp_nav_menu/"><em>wp_list_categories()</em></a>.  I will not be covering the specific use for each function&#8217;s arguments; the idea is to help show how these options correlate to one another.</p>
<p>Let&#8217;s start with the full default of <em>wp_nav_menu()</em><sup> 1</sup> explicitly displayed:</p>
<pre class="brush: php; title: ; notranslate">
wp_nav_menu( array(
    'menu'              =&gt; '',
    'container'         =&gt; 'div',
    'container_class'   =&gt; '',
    'container_id'      =&gt; '',
    'menu_class'        =&gt; 'menu',
    'menu_id'           =&gt; '',
    'echo'              =&gt; true,
    'fallback_cb'       =&gt; 'wp_page_menu',
    'before'            =&gt; '',
    'after'             =&gt; '',
    'link_before'       =&gt; '',
    'link_after'        =&gt; '',
    'depth'             =&gt; 0,
    'walker'            =&gt; '',
    'theme_location'    =&gt; ''
    ) );
</pre>
<p>Followed by the same explicit defaults of <em>wp_page_menu()</em><sup> 2, 3</sup>:</p>
<pre class="brush: php; title: ; notranslate">
wp_page_menu( array(
    'sort_column'       =&gt; 'menu_order, post_title',
    'include'           =&gt; '',
    'exclude'           =&gt; '',
    'show_home'         =&gt; false,
    'menu_class'        =&gt; 'menu',
    'echo'              =&gt; true,
    'link_before'       =&gt; '',
    'link_after'        =&gt; ''
    ) );
</pre>
<p>Now onto updating <em>wp_page_menu()</em> to <em>wp_nav_menu()</em>, which turns out to be rather simple.</p>
<p>Here is the break-down of the <em>wp_page_menu()</em> default options from above:</p>
<ul>
<li><code>'sort_column'</code> &#8211; not used</li>
<li><code>'include'</code> &#8211; not used</li>
<li><code>'exclude'</code> &#8211; not used</li>
<li><code>'show_home'</code> &#8211; not used (see bonus section below)</li>
<li><code>'menu_class'</code> &#8211; same as wp_nav_menu()</li>
<li><code>'echo'</code> &#8211; same as wp_nav_menu()</li>
<li><code>'link_before'</code> &#8211; same as wp_nav_menu()</li>
<li><code>'link_after'</code> &#8211; same as wp_nav_menu()</li>
</ul>
<p>First off &#8216;sort_column&#8217;, &#8216;include&#8217;, and &#8216;exclude&#8217; are replaced by the end-user&#8217;s choices using the <abbr title="User Interface">UI</abbr> of <em>wp_nav_menu()</em> found under Appearance | Menu in the dashboard. The balance of the default options are the same in <em>wp_nav_menu()</em>, with the exception of <code>'show_home' => false</code> which is the &#8220;bonus&#8221; content.</p>
<p>Upgrading from <em>wp_page_menu()</em> to <em>wp_nav_menu()</em> may be as easy as a simple find and replace operation.</p>
<div class="bonus">
<em>Bonus</em> &#8211; Although the default in <em>wp_page_menu()</em> does not show a home page link you can add a custom menu item in <em>wp_nav_menu()</em> if you want one to appear. You may need to edit your theme to remove the orginal &#8220;home&#8221; link if one was being generated before upgrading.
</div>
<div class="nota-bene">
NB: You may also need to add this line of code to your &#8216;functions.php&#8217; template file to add custom menu support to your theme: <code>add_theme_support( 'menus' );</code>
</div>
<div class="footnote">
<ol>Resources:</p>
<li><a href="http://core.trac.wordpress.org/browser/trunk/wp-includes/nav-menu-template.php">../wp-includes/nav-menu-template.php</a></li>
<li><a href="http://core.trac.wordpress.org/browser/trunk/wp-includes/post-template.php">../wp-includes/post-template.php</a></li>
<li><a href="http://codex.wordpress.org/Function_Reference/wp_page_menu">Function Reference/wp page menu</a></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://wpfirstaid.com/2010/07/upgrade-wp_page_menu-to-wp_nav_menu/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>WordPress 3.0 Navigation Menu Styles</title>
		<link>http://wpfirstaid.com/2010/03/wordpress-3-0-navigation-menu-styles/</link>
		<comments>http://wpfirstaid.com/2010/03/wordpress-3-0-navigation-menu-styles/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 14:19:05 +0000</pubDate>
		<dc:creator>The Doctor</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[register_sidebar]]></category>
		<category><![CDATA[settings]]></category>
		<category><![CDATA[widget]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[wp_nav_menu]]></category>

		<guid isPermaLink="false">http://wpfirstaid.com/?p=418</guid>
		<description><![CDATA[A list of WordPress version 3.0 Navigation Menu default widget, and wp_nav_menu() function, generated CSS style elements.]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s jump right in &#8230;</p>
<p>Using the default definition from the <em><a href="http://codex.wordpress.org/Function_Reference/register_sidebar">register_sidebar()</a></em> function found in <em>../wp-includes/widgets.php</em> of WordPress version <del>3.0-alpha</del> 3.0-beta1<sup>2</sup> (see below):</p>
<pre class="brush: php; first-line: 551; title: ; notranslate">
	$defaults = array(
		'name' =&gt; sprintf(__('Sidebar %d'), $i ),
		'id' =&gt; &quot;sidebar-$i&quot;,
		'description' =&gt; '',
		'before_widget' =&gt; '&lt;li id=&quot;%1$s&quot; class=&quot;widget %2$s&quot;&gt;',
		'after_widget' =&gt; &quot;&lt;/li&gt;\n&quot;,
		'before_title' =&gt; '&lt;h2 class=&quot;widgettitle&quot;&gt;',
		'after_title' =&gt; &quot;&lt;/h2&gt;\n&quot;,
	);
</pre>
<p>&#8230; and the default Navigation Menu widget, the following CSS style elements are generated:</p>
<ul>
<li>#nav-menu-&lt;widget instance></li>
<li>.widget</li>
<li>.widget_nav_menu</li>
<li>.widgettitle</li>
</ul>
<p>&#8230; with these elements generated specifically by the <em><a href="http://codex.wordpress.org/Function_Reference/wp_nav_menu">wp_nav_menu()</a></em> function found in <em>../wp-includes/default-widgets.php</em> of WordPress version <del>3.0-alpha</del> 3.0-beta1<sup>2</sup>:</p>
<ul>
<li>.menu-&lt;menu name>-container<sup>2</sup></li>
<li>#menu-&lt;menu name></li>
<li>.menu</li>
<li>#menu-item-&lt;unique identifier*></li>
<li><del>.menu-item-type-&lt;types: page, category, Custom></del><sup>1</sup></li>
<li>.menu-item<sup>2</sup></li>
<li>.menu-item-type-&lt;post_type, custom, or taxonomy><sup>2</sup></li>
<li>.menu-item-object-&lt;page, or category><sup>2</sup></li>
<li>.current_page_item</li>
<li>.sub-menu<sup>1</sup></li>
</ul>
<p>This is just an initial listing of my observations as of the March 16, 2010 3.0-alpha version of WordPress. Look for future updates; and, please feel free to make note of your own observations below.</p>
<p><em>Bonus</em> &#8211; A suggested addition to style.css for theme developers:</p>
<pre class="brush: css; title: ; notranslate">
/* WordPress 3.0 Navigation Menu default widget */
.widget_nav_menu .menu {margin: 0;}
.widget_nav_menu .menu li {
  display: block;
  float: none;
  /* text-align: left; */
}
</pre>
<div class="nota-bene"><abbr title="Nota Bene">*N.B.</abbr> &#8211; each new menu item generates its own post ID in the WordPress database &#8216;posts&#8217; table. This appears to be in a similar fashion to post revisions.</div>
<div class="footnote">
<ol>Notes:</p>
<li>Mar 21, 2010
<ul>
<li>menu item type class further defined</li>
<li>sub-menu class noted</li>
</ul>
</li>
<li>Apr 15, 2010 (3.0-beta1 updates)
<ul>
<li>additional menu classes defined and/or modified</li>
<li>new menu container class noted</li>
</ul>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://wpfirstaid.com/2010/03/wordpress-3-0-navigation-menu-styles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

