<?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>WordPress Hacks &#187; WordPress Menu</title>
	<atom:link href="http://wphacks.com/tag/wordpress-menu/feed/" rel="self" type="application/rss+xml" />
	<link>http://wphacks.com</link>
	<description>WordPress Themes, Plugins, Hacks, Tutorials, and more!</description>
	<lastBuildDate>Sun, 28 Feb 2010 15:36:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>CSS Techniques: Using Sliding Doors with Wordpress Navigation</title>
		<link>http://wphacks.com/sliding-doors-wordpress-navigation-css-technique/</link>
		<comments>http://wphacks.com/sliding-doors-wordpress-navigation-css-technique/#comments</comments>
		<pubDate>Mon, 30 Jun 2008 06:00:54 +0000</pubDate>
		<dc:creator>Jean-Baptiste Jung</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[CSS Techniques]]></category>
		<category><![CDATA[WordPress Code]]></category>
		<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[WordPress How-To]]></category>
		<category><![CDATA[WordPress Menu]]></category>

		<guid isPermaLink="false">http://wphacks.com/?p=642</guid>
		<description><![CDATA[The <em>sliding doors</em> CSS hack allows you to create sophisticated tabs for your navigation bar. Sadly, Wordpress core functions <em>wp_list_pages()</em> and <em>wp_list_categories()</em> doesn't allow you to add the required <em>span</em> tag to use this technique.
We are goind to see how to proceed in order to use <em>sliding doors</em> in our Wordpress theme.]]></description>
			<content:encoded><![CDATA[<p style="float: right;margin: 4px;"><a href="http://gabfirethemes.com/"><img src="http://www.gabfirethemes.com/wp-content/themes/gabthemes/images/promoGabfire.gif"></a></p><p>This <em>sliding doors</em> CSS hack allows you to create sophisticated tabs for your navigation bar. Sadly, Wordpress core functions <em>wp_list_pages()</em> and <em>wp_list_categories()</em> don&#8217;t allow you to add the required <em>span</em> tag to use this technique.</p>
<p>We are going to see how to proceed in order to use <em>sliding doors</em> in our Wordpress theme.</p>
<h2>Sliding doors, why?</h2>
<p>There&#8217;s many articles available on the web about the <em>sliding doors</em> technique, so I&#8217;m not going to talk a lot about it. For people who don&#8217;t already know this famous hack, here&#8217;s a quick example.</p>
<p>Let&#8217;s build a typical navigation list:</p>
<p><code>&lt;ul id="nav"&gt;<br />
&lt;li&gt;&lt;a href="#"&gt;link n°1&lt;/a&gt;&lt;/li&gt;<br />
&lt;li&gt;&lt;a href="#"&gt;link n°2&lt;/a&gt;&lt;/li&gt;<br />
&lt;li&gt;&lt;a href="#"&gt;link n°3&lt;/a&gt;&lt;/li&gt;<br />
&lt;/ul&gt;</code></p>
<p>If we apply, via CSS, background images to our links in order to make this menu prettier, we&#8217;ll quickly see a big problem: We must add a fixed width to the links, otherwise the image will be truncated if the link is too short, or the link will overflow the image if its width is too long.</p>
<p>That&#8217;s why <em>sliding doors</em> are very useful: We just have to add a <em>span</em> element inside the link, and then, in our CSS, assign a different background image to both the span element and the link.</p>
<p><code>&lt;ul id="nav"&gt;<br />
&lt;li&gt;&lt;a href="#"&gt;&lt;span&gt;link n°1&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;<br />
&lt;li&gt;&lt;a href="#"&gt;&lt;span&gt;link n°2&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;<br />
&lt;li&gt;&lt;a href="#"&gt;&lt;span&gt;link n°3&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;<br />
&lt;/ul&gt;</code></p>
<p>Our CSS should look like this:</p>
<p><code>#nav a, #nav a:visited {<br />
display:block;<br />
}<br />
#nav a:hover, #nav a:active {<br />
background:url(images/tab-right.jpg) no-repeat 100% 1px;<br />
float:left;<br />
}<br />
#nav a span {<br />
float:left;<br />
display:block;<br />
}<br />
#nav a:hover span {<br />
float:left;<br />
display:block;<br />
background: url(images/tab-left.jpg) no-repeat 0 1px;<br />
}</code></p>
<p><em>Please note, as this is only an example, the CSS above isn&#8217;t complete and only shows how to apply the sliding doors hack.</em></p>
<p>You can see a live demo of a navigation menu which uses this technique on my blog <a href="http://www.catswhocode.com">here.</a></p>
<p><img src="http://www.lyxia.org/blog/wp-content/uploads/2008/06/wordpress-sliding-doors-menu.jpg" alt="Wordpress sliding doors" /></p>
<h2>Using the sliding doors hack within Wordpress</h2>
<p>I saw many blog posts where some users told you to modify Wordpress core in order to apply this technique. Personally, I never really liked this idea: First, the Wordpress core wasn&#8217;t made for being modified. And secondly, if you do, when you&#8217;ll upgrade your WP version, you&#8217;ll have to re-modify the core. Not user friendly at all!</p>
<p>Instead of this, let&#8217;s use a regular expression, by using the php <em>preg_replace()</em> function. We are going to get our pages (or categories) without displaying it, and passing it as a parameter to <em>preg_replace()</em>. The two remaining parameters will be, of course, our regular expression: The pattern we&#8217;re looking for, and this pattern&#8217;s replacement.</p>
<p>To create this menu, paste the following code instead of the <em>wp_list_pages()</em> (or <em>wp_list_categories()</em>) function in the <em>header.php</em> of your Wordpress theme.</p>
<p>To list your pages:</p>
<p><code>&lt;ul id="nav"&gt;<br />
&lt;li&gt;&lt;a href="&lt;?php echo get_option('home'); ?&gt;/"&gt;&lt;span&gt;Home&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;<br />
&lt;?php echo preg_replace('@\&lt;li([^&gt;]*)&gt;\&lt;a([^&gt;]*)&gt;(.*?)\&lt;\/a&gt;@i', '&lt;li$1&gt;&lt;a$2&gt;&lt;span&gt;$3&lt;/span&gt;&lt;/a&gt;', wp_list_pages('echo=0&amp;orderby=name&amp;exlude=181&amp;title_li=&amp;depth=1')); ?&gt;<br />
&lt;/ul&gt;</code></p>
<p>To list your categories:</p>
<p><code>&lt;ul id="nav"&gt;<br />
&lt;li&gt;&lt;a href="&lt;?php echo get_option('home'); ?&gt;/"&gt;&lt;span&gt;Home&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;<br />
&lt;?php echo preg_replace('@\&lt;li([^&gt;]*)&gt;\&lt;a([^&gt;]*)&gt;(.*?)\&lt;\/a&gt;@i', '&lt;li$1&gt;&lt;a$2&gt;&lt;span&gt;$3&lt;/span&gt;&lt;/a&gt;', wp_list_categories('echo=0&amp;orderby=name&amp;exlude=181&amp;title_li=&amp;depth=1')); ?&gt;<br />
&lt;/ul&gt;</code></p>
<p>Right now, your new menu is ready. You just have to make it sexy with CSS. Have fun! <img src='http://wphacks.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img src="http://wphacks.com/?ak_action=api_record_view&id=330&type=feed" alt="" /><p></p><p>You are reading <a href="http://wphacks.com/sliding-doors-wordpress-navigation-css-technique/">CSS Techniques: Using Sliding Doors with Wordpress Navigation</a>  © 2008 | <a href="http://wphacks.com">WordPress Hacks</a> | <a href="http://wpnexus.com">WordPress Directory</a> | <a href="http://wpforums.com/">WordPress Forums</a> | <a href="http://wpebook.com/">WordPress eBook</a></p>

<p><small>Enjoy writing about WordPress?  Get your blog more exposure by joining the <a href="http://wphacks.com/write/">WordPress Hacks writing team</a>!</small></p>]]></content:encoded>
			<wfw:commentRss>http://wphacks.com/sliding-doors-wordpress-navigation-css-technique/feed/</wfw:commentRss>
		<slash:comments>48</slash:comments>
		</item>
		<item>
		<title>How To: Making a Categories Drop-Down Menu</title>
		<link>http://wphacks.com/how-to-make-categories-drop-down-menu/</link>
		<comments>http://wphacks.com/how-to-make-categories-drop-down-menu/#comments</comments>
		<pubDate>Thu, 15 May 2008 09:00:41 +0000</pubDate>
		<dc:creator>Jean-Baptiste Jung</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[WordPress How-To]]></category>
		<category><![CDATA[WordPress Menu]]></category>

		<guid isPermaLink="false">http://wphacks.com/?p=556</guid>
		<description><![CDATA[This guest post was written by Jean-Baptiste Jung, who maintains a blog (written in French) that covers WordPress. If you have webmaster or WordPress knowledge and are interested in writing a post for Hack WordPress, please contact us.
Tired of your old navigation? So, what about creating a Magazine-style drop-down menu?
I propose here a drop-down menu [...]]]></description>
			<content:encoded><![CDATA[<p><em>This guest post was written by <a href="http://www.lyxia.org">Jean-Baptiste Jung</a>, who maintains a blog (written in French) that covers WordPress. If you have webmaster or WordPress knowledge and are interested in <a href="http://wphacks.com/write">writing a post for Hack WordPress</a>, please <a href="http://wphacks.com/contact">contact us</a>.</em></p>
<p>Tired of your old navigation? So, what about creating a Magazine-style drop-down menu?</p>
<p>I propose here a drop-down menu listing your pages and sub pages, including one last item to show up your categories directly in the menu.</p>
<p><img src="http://www.lyxia.org/blog/wp-content/uploads/2008/03/menu-pages-categories-wordpress.png" alt="" width="500" height="300" /></p>
<h3>HTML and PHP</h3>
<p>We will start by using WordPress core functions in order to retrieve our pages and categories. Edit the <em>header.php</em> of your theme, and replace your old nav code by this one:</p>
<p><code>&lt;ul id="nav" class="clearfloat"&gt;<br />
&lt;li&gt;&lt;a href="&lt;?php echo get_option('home'); ?&gt;/" class="on"&gt;Home&lt;/a&gt;&lt;/li&gt;<br />
&lt;?php wp_list_pages('title_li='); ?&gt;<br />
&lt;li class="cat-item"&gt;&lt;a href="#"&gt;Categories&lt;/a&gt;<br />
&lt;ul class="children"&gt;<br />
&lt;?php wp_list_categories('orderby=name&amp;title_li=');<br />
$this_category = get_category($cat);<br />
if (get_category_children($this_category-&gt;cat_ID) != "") {<br />
echo "&lt;ul&gt;";<br />
wp_list_categories('orderby=id&amp;show_count=0&amp;title_li=<br />
&amp;use_desc_for_title=1&amp;child_of='.$this_category-&gt;cat_ID);<br />
echo "&lt;/ul&gt;";<br />
}<br />
?&gt;<br />
&lt;/ul&gt;<br />
&lt;/li&gt;<br />
&lt;/ul&gt;</code></p>
<p>This code will make a list of all our pages and subpages, as well as a last list element named &#8220;Categories&#8221;. When an user will hover top level pages (in case of a page menu) or top level categories, we will show up the related sub pages/categories.</p>
<h3>CSS</h3>
<p>Even if the code is fully functional, our script needs a good CSS styling. This CSS, which was taken from <a href="http://www.darrenhoyt.com/">Darren Hoyt&#8217;s</a> free Mimbo Theme, is perfect for what we want to do.</p>
<p><code>#nav{<br />
background:#222;<br />
font-size:1.1em;<br />
}<br />
#nav, #nav ul {<br />
list-style: none;<br />
line-height: 1;<br />
}<br />
#nav a, #nav a:hover {<br />
display: block;<br />
text-decoration: none;<br />
border:none;<br />
}<br />
#nav li {<br />
float: left;<br />
list-style:none;<br />
border-right:1px solid #a9a9a9;<br />
}<br />
#nav a, #nav a:visited {<br />
display:block;<br />
font-weight:bold;<br />
color: #f5f5f4;<br />
padding:6px 12px;<br />
}<br />
#nav a:hover, #nav a:active, .current_page_item a, #home .on {<br />
background:#000;<br />
text-decoration:none<br />
}<br />
#nav li ul {<br />
position: absolute;<br />
left: -999em;<br />
height: auto;<br />
width: 174px;<br />
border-bottom: 1px solid #a9a9a9;<br />
}<br />
#nav li li {<br />
width: 172px;<br />
border-top: 1px solid #a9a9a9;<br />
border-right: 1px solid #a9a9a9;<br />
border-left: 1px solid #a9a9a9;<br />
background: #777;<br />
}<br />
#nav li li a, #nav li li a:visited {<br />
font-weight:normal;<br />
font-size:0.9em;<br />
color:#FFF;<br />
}<br />
#nav li li a:hover, #nav li li a:active {<br />
background:#000;<br />
}<br />
#nav li:hover ul, #nav li li:hover ul, #nav li li li:hover ul, #nav li.sfhover ul, #nav li li.sfhover ul, #nav li li li.sfhover ul {<br />
left: auto;<br />
}<br />
a.main:hover {<br />
background:none;<br />
}</code></p>
<h3>Javascript</h3>
<p>Modern browsers (Safari, Firefox, Opera, and even Internet Explorer 7) will not have any problem with the <em>:hover</em> pseudo-class on <em>li</em> elements. But as we can easily guess it, the obsolete IE6 can&#8217;t deal with that.</p>
<p>In order to make our script compatible with IE6, we&#8217;ll need to charge this little unobtrusive Javascript code, in the <em>head</em> section our our HTML document, or even better, in a separate .js file.</p>
<p><code><!--//-->&lt;![CDATA[//&gt;&lt;!--<br />
sfHover = function() {<br />
var sfEls = document.getElementById("nav").getElementsByTagName("LI");<br />
for (var i=0; i&lt;sfEls.length; i++) {<br />
sfEls[i].onmouseover=function() {<br />
this.className+=" sfhover";<br />
}<br />
sfEls[i].onmouseout=function() {<br />
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");<br />
}<br />
}<br />
}<br />
if (window.attachEvent) window.attachEvent("onload", sfHover);<br />
//--&gt;&lt;!]]&gt;</code></p>
<p>Now, your new drop-down menu is ready and will give your blog a professional look.</p>
<img src="http://wphacks.com/?ak_action=api_record_view&id=270&type=feed" alt="" /><p>You are reading <a href="http://wphacks.com/how-to-make-categories-drop-down-menu/">How To: Making a Categories Drop-Down Menu</a>  © 2008 | <a href="http://wphacks.com">WordPress Hacks</a> | <a href="http://wpnexus.com">WordPress Directory</a> | <a href="http://wpforums.com/">WordPress Forums</a> | <a href="http://wpebook.com/">WordPress eBook</a></p>

<p><small>Enjoy writing about WordPress?  Get your blog more exposure by joining the <a href="http://wphacks.com/write/">WordPress Hacks writing team</a>!</small></p>]]></content:encoded>
			<wfw:commentRss>http://wphacks.com/how-to-make-categories-drop-down-menu/feed/</wfw:commentRss>
		<slash:comments>56</slash:comments>
		</item>
	</channel>
</rss>
