WordPress Menu and Sidebars

Default Navigation Menu

<?php​ wp_nav_menu(); ​?>

Specific Navigation Menu

<?php​ wp_nav_menu( ​array​(​'menu'​ => My Navigation​' )); ?>

Category Based Navigation

<​ul​ ​id​=​"menu"​>
  <​li​ <?​php​ ​if​(​is_home​()) { ?> class="current-cat" ​<?php​ } ​?>​>
    <​a​ ​href​=​"<?php bloginfo('home'); ?>"​>Home</​a​>
  </​li​>
  ​<?php​ wp_list_categories(​'title_li=&orderby=id'​);​?>
</​ul​>

Page Based Navigation

<​ul​ ​id​=​"menu"​>
  <​li​ <?​php​ ​if​(​is_home​()) { ?> class="current-page-item" ​<?php​ } ​?>​>
    <​a​ ​href​=​"<?php bloginfo('home'); ?>"​>Home</​a​>
  </​li​>
​  <?php​ wp_list_pages(​'sort_column=menu_order&depth=1&title_li='​);?​ >
</​ul​>

Registering New Sidebar

Add the following code to your functions.php file to register a new sidebar.

add_action( ​'widgets_init'​, ​'theme_slug_widgets_init'​ );
function​ ​theme_slug_widgets_init​() {
  register_sidebar( ​array​(
​    'name'​ => __( ​'My Sidebar'​, ​'theme-slug'​ ),
​    'id'​ => ​'sidebar-1'​,
​    'description'​ => __( ​'Description',​ ​'theme-slug'​ ),
    'before_widget'​ => ​'<li id="%1$s" class="widget %2$s">'​,
    'after_widget'​ => ​'</li>'​,
    ​'before_title'​ => ​'<h2 class="widgettitle">'​,
​    'after_title'​ => ​'<h2>'​,
  ));
}
Comments