<?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_list_pages</title>
	<atom:link href="http://wpfirstaid.com/tag/wp_list_pages/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_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>Going Home</title>
		<link>http://wpfirstaid.com/2009/11/going-home/</link>
		<comments>http://wpfirstaid.com/2009/11/going-home/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 20:29:29 +0000</pubDate>
		<dc:creator>The Doctor</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[bloginfo]]></category>
		<category><![CDATA[get_bloginfo]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[wp_list_categories]]></category>
		<category><![CDATA[wp_list_pages]]></category>
		<category><![CDATA[wp_page_menu]]></category>

		<guid isPermaLink="false">http://wpfirstaid.com/?p=5</guid>
		<description><![CDATA[Examples of adding a home page link to a WordPress theme with code that can be easily copied and pasted.]]></description>
			<content:encoded><![CDATA[<p>Creating text links back to the home page, or front page, of a blog are done in many ways. Many themes use the blog Title as a link back to the home page. It is also very common for the menu or navigation bar to link to the home page. This article will cover some examples of links for going home.</p>
<p>Let&#8217;s start with an obvious example: a link from the blog title back to the home page.</p>
<pre class="brush: php; gutter: false; title: ; notranslate">&lt;a href=&quot;http://wpfirstaid.com/&quot;&gt;WP First Aid&lt;/a&gt;</pre>
<p>The above example is very, very basic &#8230; let&#8217;s dress it up a bit:</p>
<pre class="brush: php; gutter: false; html-script: true; title: ; notranslate">&lt;h1 class=&quot;blog-title&quot;&gt;&lt;a href=&quot;http://wpfirstaid.com/&quot; alt=&quot;Going Home: WP First Aid&quot;&gt;WP First Aid&lt;/a&gt;&lt;/h1&gt;</pre>
<p>Now we have a title using the <code>h1</code> element and a CSS class of <code>blog-title</code> with some <code>alt</code> text letting the reader know where the link will be going. This is better but how does this help you? Let&#8217;s make use of WordPress&#8217; built in functions to make this example more generic and easily transferable.</p>
<pre class="brush: php; gutter: false; title: ; notranslate">&lt;h1 class=&quot;blog-title&quot;&gt;&lt;a href=&quot;&lt;?php bloginfo('url'); ?&gt;&quot; alt=&quot;Going Home: &lt;?php bloginfo('name'); ?&gt;&quot;&gt;&lt;?php bloginfo('name'); ?&gt;&lt;/a&gt;&lt;/h1&gt;</pre>
<p>This example makes use of the WordPress function <code>bloginfo()</code>. Here is a link to the <a href="http://codex.wordpress.org/Template_Tags/bloginfo">WordPress codex</a> for this function; and, here is a link to the <a href="http://codex.wordpress.org/Function_Reference/get_bloginfo"><code>get_bloginfo()</code></a> function which provides additional details.</p>
<p>Our next example is adding a home page link to a navigation bar. Many navigation bars are generated with one of three WordPress functions: <a href="http://codex.wordpress.org/wp_list_pages"><code>wp_list_pages()</code></a>, <a href="http://codex.wordpress.org/Template_Tags/wp_page_menu"><code>wp_page_menu()</code></a>, or <a href="http://codex.wordpress.org/Template_Tags/wp_list_categories"><code>wp_list_categories()</code></a>. The wp_page_menu function uses a value that creates a home page link, for example:</p>
<pre class="brush: php; gutter: false; title: ; notranslate">&lt;?php wp_page_menu('show_home=1'); ?&gt;</pre>
<p>The wp_page_menu function includes all the available parameters of the wp_list_pages function and also includes wrapping the output in an unordered list.</p>
<p>To add a home page link into a theme using the wp_list_pages function you may look at the following example for guidance:</p>
<pre class="brush: php; first-line: 10; highlight: [12]; title: ; notranslate">&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;&lt;?php bloginfo('url'); ?&gt;&quot; alt=&quot;Going Home: &lt;?php bloginfo('name'); ?&gt;&quot;&gt;&lt;?php bloginfo('name'); ?&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;?php wp_list_pages(); ?&gt;
&lt;/ul&gt;</pre>
<p>Adding a home page link to a navigation menu created with the wp_list_categories function is very similar. Let&#8217;s take a quick look at it below.</p>
<pre class="brush: php; first-line: 10; highlight: [12]; title: ; notranslate">&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;&lt;?php bloginfo('url'); ?&gt;&quot; alt=&quot;Going Home: &lt;?php bloginfo('name'); ?&gt;&quot;&gt;&lt;?php bloginfo('name'); ?&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;?php wp_list_categories(); ?&gt;
&lt;/ul&gt;</pre>
<p>The only difference in the above two examples are the function call. The links we added to the home page are almost identical to the the link example we used for the blog title. </p>
<p>Feel free to use any of the above examples in your own works. Of course, there could be additional CSS elements needed to work with your theme&#8217;s style but I will leave that as an exercise for you &#8230; or feel free to contact us with more complex code requirements.</p>
]]></content:encoded>
			<wfw:commentRss>http://wpfirstaid.com/2009/11/going-home/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

