Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Custom Menu Support for WordPress Themes


Published on

Adding Support for WordPress Custom Navigation Menus to your WordPress Theme.

Published in: Technology, Business

Custom Menu Support for WordPress Themes

  1. 1. WordCamp Chicago 2010 Custom Navigation Menus: You know you want them. Daisy Olsen Twitter: @DaisyOlsen
  2. 2. Template Tags <ul><li>A PHP function defined in the WordPress core designed to add dynamic elements & content to your theme </li></ul><ul><ul><li>wp_list_pages(); </li></ul></ul><ul><ul><li>wp_list_categories(); </li></ul></ul><ul><ul><li>the_content(); </li></ul></ul><ul><ul><li>the_excerpt(); </li></ul></ul><ul><li> </li></ul>
  3. 3. Adding Feature Support <ul><li>When a backend component exists the process begins in functions.php </li></ul><ul><li>Register Sidebars As seen in most modern themes </li></ul><ul><li>Register Menus register_nav_menu( 'primary-menu', __( 'Primary Menu' ) ); </li></ul><ul><li>Enable Custom Background add_custom_background(); </li></ul>
  4. 4. Template Tag Parameters <ul><li>Instructions given to the function </li></ul><ul><li>Most template tags have parameters </li></ul><ul><li>Codex page for the template tag is the best way to see what parameters are available </li></ul>
  5. 5. Template Tags Used for Navigation <ul><li>wp_list_categories(); </li></ul><ul><li>wp_list_pages(); </li></ul><ul><li>wp_nav_menu(); </li></ul>
  6. 6. Functions used for Custom Menus <ul><li>wp_nav_menu(); Template Tag to Insert Menu into Theme </li></ul><ul><li>register_nav_menu(); Register a single menu location. </li></ul><ul><li>register_nav_menus(); Register more than one menu locations </li></ul>
  7. 7. Original Code – Categories <ul><li><div id=&quot;catnav&quot;> </li></ul><ul><li><ul id=&quot;nav&quot;> </li></ul><ul><li><?php wp_list_categories('orderby=name&title_li='); ?> </li></ul><ul><li></ul> </li></ul><ul><li></div> </li></ul>
  8. 8. Register Menu Location <ul><li>//Register Navigation Menus </li></ul><ul><li>if (function_exists('register_nav_menus')) : </li></ul><ul><li>register_nav_menus(array( 'topmenu' => __('Top Menu'), 'catnav' => __('Cat Nav') </li></ul><ul><li>)); </li></ul><ul><li>endif; </li></ul>
  9. 9. Custom Navigation Version <ul><li><div id=&quot;catnav&quot;> <div id=&quot;nav&quot;> <?php wp_nav_menu( array( 'theme_location' => 'catnav' ) ); ?> </div> </div><!-- /catnav --> </li></ul>