<?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 Engineer &#187; Menu Icon</title> <atom:link href="http://wpengineer.com/tag/menu-icon/feed/" rel="self" type="application/rss+xml" /><link>http://wpengineer.com</link> <description>WordPress News, Hacks, Tipps, Tutorials, Plugins and Themes</description> <lastBuildDate>Wed, 28 Jul 2010 13:37:05 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=4681</generator> <xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" /> <item><title>Top Level Menu In WordPress 2.7</title><link>http://wpengineer.com/top-level-menu-in-wordpress-27/</link> <comments>http://wpengineer.com/top-level-menu-in-wordpress-27/#comments</comments> <pubDate>Tue, 09 Dec 2008 13:20:40 +0000</pubDate> <dc:creator>Frank</dc:creator> <category><![CDATA[WordPress Hacks]]></category> <category><![CDATA[Menu Icon]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Plugin]]></category> <category><![CDATA[WordPress]]></category> <category><![CDATA[WordPress Plugins]]></category><guid
isPermaLink="false">http://wpengineer.com/?p=475</guid> <description><![CDATA[I explained in one of my previous posts how to add a nice icon to your Plugin in the backend are of WordPress 2.7. Some of my readers on my German blog asked how to add an icon to menus in the top level. I thought there are more readers interested to know about it, [...]]]></description> <content:encoded><![CDATA[<p><img
src="http://wpengineer.com/blog/wp-content/uploads/wp27_mymenu.png" alt="" title="wp27_mymenu" width="261" height="139" class="alignright size-full wp-image-476" /><br
/> I explained in one of my <a
href="http://wpengineer.com/how-to-improve-wordpress-plugins/" class="liinternal">previous posts</a> how to add a nice icon to your Plugin in the backend are of WordPress 2.7. Some of my readers on my German blog asked how to add an icon to menus in the top level. I thought there are more readers interested to know about it, therefore I will show it here including a hover effect for the icon.<br
/> <span
id="more-475"></span></p><h3><code>add_menu_page()</code></h3><p>The function <code>add_menu_page()</code> exists since the beginning of WordPress and got a parameter added in WordPress 2.7 &#8211; <code>$icon_url</code>.</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;">add_menu_page<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$page_title</span><span style="color: #339933;">,</span> <span style="color: #000088;">$menu_title</span><span style="color: #339933;">,</span> <span style="color: #000088;">$access_level</span><span style="color: #339933;">,</span> <span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$function</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$icon_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span> <span style="color: #009900;">&#41;</span></pre></div></div><p>This parameter can either send a path of the icon or a <code>div</code>, which can be addressed via CSS style. Additionally I like to show you how to implement the hover effect, which is standard in version 2.7.</p><h3>Plugin example</h3><p>Here is a little example to understand. I created the Plugin as you can see below and put it in the folder <code>/plugins/</code> of the WP installation.<br
/> &rarr; Plugins<br
/> &nbsp;&nbsp;&nbsp;&rarr; test<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&rarr; css<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&rarr; style.css<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&rarr; images<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&rarr; fb_menu.png<br
/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&rarr; test.php</p><p>The Plugin includes the function to create the menu item in the top level area. Therefore we deliver the value <em>div</em> as last parameter.<br
/> In addition we call the function via hook, so that the menu item will be created and the content of the function will be available.</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> add_menu_page_in_27<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	add_menu_page<span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Test'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Test Description'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">9</span><span style="color: #339933;">,</span> <span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'div'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_menu'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'add_menu_page_in_27'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><h3>Icon via CSS Sprites</h3><p><img
class="alignright" src="http://bueltge.de/wp-content/images/wp27/fb_menu.png" alt="Menu Icon for menu WordPress 2.7" /><br
/> Now the HTML is in the backend and we use CSS to create the icon. I use the possibility of <a
href="http://www.alistapart.com/articles/sprites/" class="liexternal">CSS Sprites</a>.</p><p>I add an icon into the Plugin, which contains both conditions. See image on the right.</p><p>The associated CSS looks like below, which I placed in the folder css of the Plugin.  Thereby the ID of the menu item will be created by the name of the file &#8211; <code>toplevel_page_test</code> = <code>toplevel_page_</code> + <code>test.php</code>.</p><div
class="wp_syntax"><div
class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#adminmenu</span> <span style="color: #cc00cc;">#toplevel_page_test</span> div<span style="color: #6666ff;">.wp-menu-image</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">transparent</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'../images/fb_menu.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #993333;">scroll</span> <span style="color: #933;">-1px</span> <span style="color: #933;">-33px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#adminmenu</span> <span style="color: #cc00cc;">#toplevel_page_test</span><span style="color: #3333ff;">:hover </span>div.wp-menu-image<span style="color: #00AA00;">,</span>
<span style="color: #cc00cc;">#adminmenu</span> <span style="color: #cc00cc;">#toplevel_page_test</span><span style="color: #6666ff;">.wp-has-current-submenu</span> div.wp-menu-image<span style="color: #00AA00;">,</span>
<span style="color: #cc00cc;">#adminmenu</span> <span style="color: #cc00cc;">#toplevel_page_test</span><span style="color: #6666ff;">.current</span> div<span style="color: #6666ff;">.wp-menu-image</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">transparent</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'../images/fb_menu.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #993333;">scroll</span> <span style="color: #933;">-1px</span> <span style="color: #933;">-1px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;">wp_enqueue_style<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'test_css'</span><span style="color: #339933;">,</span> plugins_url<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$path</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/test/css/style.css'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><h3>Conclusion</h3><p>This is a clear and neat solution, which can be also integrated into small functions, if you query of wp-version basis.</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">version_compare</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$wp_version</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'2.6.999'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&gt;'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #666666; font-style: italic;">// since Version 2.6.999</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #666666; font-style: italic;">// less than Version 2.6.999</span>
<span style="color: #009900;">&#125;</span></pre></div></div><h3>Download</h3><p>You can donwload this example on my private blog - <a
href="http://bueltge.de/menu-seite-ab-wordpress-27-hinzufuegen/845/#download" class="liexternal">download page</a><br
/><hr
/><h3>Related posts:</h3><ul><li><a
href="http://wpengineer.com/wordpress-3-0-nav-menu-ui-update/" rel="bookmark" title="Permanent Link: WordPress 3.0 Nav Menu UI Update" class="liinternal">WordPress 3.0 Nav Menu UI Update</a></li><li><a
href="http://wpengineer.com/wordpress-3-0-menu-update/" rel="bookmark" title="Permanent Link: WordPress 3.0 Menu Update" class="liinternal">WordPress 3.0 Menu Update</a></li><li><a
href="http://wpengineer.com/wordpress-plugin-path/" rel="bookmark" title="Permanent Link: WordPress Plugin-Path" class="liinternal">WordPress Plugin-Path</a></li><li><a
href="http://wpengineer.com/new-screenshots-of-wordpress-3-0/" rel="bookmark" title="Permanent Link: New Screenshots Of WordPress 3.0" class="liinternal">New Screenshots Of WordPress 3.0</a></li><li><a
href="http://wpengineer.com/quick-view-on-wordpress-settings/" rel="bookmark" title="Permanent Link: Quick View on WordPress Settings" class="liinternal">Quick View on WordPress Settings</a></li></ul><hr
/><p><img
style="float:left;" src="http://wpengineer.com/favicon.ico" alt="WP Engineer Favicon"/> Thanks for subscribing our feed! <a
href="http://buysellads.com/buy/detail/3646/" class="liexternal">Sponsor the WP Engineer Blog</a> and get your brand in front of several hundred users per day!<br
/> &copy; <a
href="http://wpengineer.com/" class="liinternal">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p> ]]></content:encoded> <wfw:commentRss>http://wpengineer.com/top-level-menu-in-wordpress-27/feed/</wfw:commentRss> <slash:comments>7</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Database Caching 23/34 queries in 0.213 seconds using disk
Object Caching 458/522 objects using disk

Served from: wpengineer.com @ 2010-07-29 13:07:15 -->