<?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/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>Anthology of Ideas &#187; drop-down menus</title>
	<atom:link href="http://anthologyoi.com/tag/drop-down-menus/feed" rel="self" type="application/rss+xml" />
	<link>http://anthologyoi.com</link>
	<description>Anthology of Ideas is an archive of thoughts and form.</description>
	<lastBuildDate>Sat, 03 Mar 2012 11:16:55 +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>Displaying WordPress categories in a horizontal dropdown menu.</title>
		<link>http://anthologyoi.com/wordpress/displaying-wordpress-categories-in-a-horizontal-dropdown-menu.html</link>
		<comments>http://anthologyoi.com/wordpress/displaying-wordpress-categories-in-a-horizontal-dropdown-menu.html#comments</comments>
		<pubDate>Wed, 16 Jan 2008 18:05:51 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Asides]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[categories]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[drop-down menus]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[themes]]></category>

		<guid isPermaLink="false">http://anthologyoi.com/wordpress/displaying-wordpress-categories-in-a-horizontal-dropdown-menu.html</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p> One of my readers recently asked how I created my horizontal menu bar: the short answer is by mixing CSS and Javascript.</p>
<p>The first step is to get WordPress to display the menu as a hierarchical list without a title. <span class="inline-code">&lt;?php wp_list_categories(&#039;sort_column=name&amp;sort_order=asc&amp;style=list&amp;children=true&amp;hierarchical=true&amp;title_li=0&#039;); ?&gt;</span></p>
<p>We then wrap this WordPress code in the following so we can style it.<br />
<pre class="brush: php">&lt;div style=&quot;text-align:center;&quot;&gt;
    &lt;ul id=&quot;menu&quot; style=&quot;padding:0; margin:0;&quot;&gt;
        &lt;?php wp_list_categories(&#039;sort_column=name&amp;sort_order=asc&amp;style=list&amp;children=true&amp;hierarchical=true&amp;title_li=0&#039;); ?&gt;
    &lt;/ul&gt;
&lt;/div&gt;</pre></p>
<p>I added this to my header.php, but you can add it anywhere you want it to appear.</p>
<p>The CSS is fairly simple and you just need to add it to your theme&#8217;s <u>style.css</u> file.</p>
<p><pre class="brush: php">ul#menu {
	margin: 0;
	padding: 0;
	list-style: none;
	width: 100%;
	font-size:1.2em;
}

ul#menu li {
	float: left;
	padding: 0;
	margin: 0;
	border-right:solid 1px #fff;
}

ul#menu ul li {
	float: none;
	position: relative;
	border-bottom: 1px solid #7EAED7; /* fixes gap problem in IE */
	border-left: 1px solid #FFF;
	z-index:1000;
}

ul#menu li ul {
	margin: 0;
	padding: 0;
	display:none;
	list-style: none;
	position: absolute;
	background: #9CC;
}
ul#menu ul ul{
	margin-left: .2em;
	position: absolute;
	top: 0; /* if using borders, -1px to align top borders */
	left: 100%;
}

ul#menu * a:hover, ul#menu li a:active{
background:#7EAED7 !important;
color: #FFFFFF;
}

ul#menu li a:link,
ul#menu li a:visited,
ul#menu li a:hover,
ul#menu  li a:active{
	display: block;
	padding: .2em .3em;
	text-decoration: none;
	background: #5587B3;
	 color: #FFFFFF;
}


ul#menu ul li a:link,
ul#menu ul li a:visited,
ul#menu ul li a:hover,
ul#menu ul li a:active {
	width: 8em;
}</pre></p>
<p>Of course you will need to change the colors and text sizes to ensure it blends with the rest of the theme.</p>
<p>Now the last step is the to make it work as a drop-down list on all browsers. This could be done in Firefox with a simple CSS declaration, but Internet Explorer doesn&#8217;t understand the :hover pseudo classes, so we mimic this in Javascript.</p>
<p><pre class="brush: php">&lt;script type=&quot;text/javascript&quot;&gt;
 /*&lt;![CDATA[*/

var mbA,mbT,mbTf,mbSf;
var mbR = [];

function mbSet(m) {
if (document.getElementById&amp;&amp;document.createElement) {
	var m=document.getElementById(m);
	mbR[mbR.length] = m;
	var i;

	e=m.getElementsByTagName(&#039;a&#039;);
	if (!mbTf) mbTf=new Function(&#039;mbHT();&#039;);
	if (!mbSf) mbSf=new Function(&#039;mbS(this);&#039;);
	for (i=0;i&lt;e.length;i++) {
		e[i].onmouseout=e[i].onblur=mbTf;
		e[i].onmouseover=e[i].onfocus=mbSf;
	}

	m=m.getElementsByTagName(&#039;ul&#039;);
	for (i=0;i&lt;m.length;i++) {
		mbH(mbL(m[i]));
	}
}}

function mbHA() {
	if (mbA) {
		while (mbA) mbH(mbA);
		mbHE(&#039;block&#039;);
	}
}

function mbHT() {
	if (!mbT) mbT=setTimeout(&#039;mbHA();&#039;, 0);
}

function mbTC() {
	if (mbT) {
		clearTimeout(mbT);
		mbT=null;
	}
}

function mbS(m) {
	mbTC();
	if (mbA) while (mbA&amp;&amp;m!=mbA&amp;&amp;mbP(m)!=mbA) mbH(mbA);
	else mbHE(&#039;none&#039;);

	if (mbM(m)) {
		mbSH(m,&#039;block&#039;);
		mbA=m;
	}
}

function mbH(m) {
	if (m==mbA) mbA=mbP(m);
	mbSH(m,&#039;none&#039;);
	mbT=null;
}

function mbL(m) {
	while (m &amp;&amp; m.tagName != &#039;A&#039;) m = m.previousSibling;
	return m;
}

function mbM(l) {
	while (l &amp;&amp; l.tagName != &#039;UL&#039;) l = l.nextSibling;
	return l;
}

function mbP(m) {
	var p = m.parentNode.parentNode;
	if (p.tagName == &#039;UL&#039;) {
		var i = 0;
		while (i &lt; mbR.length) {
			if (mbR[i] == p) return null;
			i++;
		}
	} else {
		return null;
	}
	return mbL(p);
}

function mbSH(m,v) {
	m.className=v;
	mbM(m).style.display=v;
}

function mbHE(v) {
	mbHEV(v,document.getElementsByTagName(&#039;select&#039;));
}

function mbHEV(v,e) {
	for (var i=0;i&lt;e.length;i++) e[i].style.display=v;
}
/*]]&gt;*/
&lt;/script&gt;</pre></p>
<p>A couple notes on the previous code. </p>
<ol>
<li>To activate it, change your theme&#8217;s &lt;body> tag to &lt;body onload=&#8221;mbSet(&#8216;menu&#8217;);></li>
<li>It was not written by me, but I&#8217;ve been using it for a long time and don&#8217;t remember where I got it. </li>
<li>It can occasionally create a JavaScript error, and I&#8217;ve intended to rewrite it for a long time, but it usually works fine. </li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://anthologyoi.com/wordpress/displaying-wordpress-categories-in-a-horizontal-dropdown-menu.html/feed</wfw:commentRss>
		<slash:comments>323</slash:comments>
		</item>
	</channel>
</rss>

