Support » Themes and Templates » Steps to Moving Primary Menu to New Sidebar Breaking in Code

  • Hey there!

    I am using a twenty twelve child theme, and this is not a twenty twelve error issue, this is a code issue. I have created a new sidebar in ‘functions’ for a shopping menu & that works, but now I would like another sidebar for the primary menu and relocate to the sidebar. So, step 1, I added this to the child functions:

    register_nav_menu( 'sidebar', __( 'Main Navigation', 'twentytwelve' ) );

    This gives me two additional sidebars I have added. First off, can you do that?

    Then I added this below it :

    'name' => __( 'Primary Menu', 'twentytwelve' ),
    		'id' => 'sidebar-5',
    		'description' => __( 'Main sidebar menu appears on all pages', 'twentytwelve' ),
    		'before_widget' => '<aside id="%1$s" class="menu %2$s">',
    		'after_widget' => '</aside>',
    		'before_title' => '<h3 class="side-menu-title">',
    		'after_title' => '</h3>',
    	) );

    *note: it took out the widget class on purpose & replaced it with menu

    Then I created a sidebar-sideNav.php,

    <?php if ( is_active_sidebar( 'sidebar-5' ) ) : ?>
    		<nav id="site-navigation" class="side-main-navigation" role="navigation">
    			<h3 class="menu-toggle"><?php _e( 'Main Navigation', 'twentytwelve' ); ?></h3>
    			<a class="assistive-text" href="#content" title="<?php esc_attr_e( 'Skip to content', 'twentytwelve' ); ?>"><?php _e( 'Skip to content', 'twentytwelve' ); ?></a>
    			<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'side-nav-menu' ) ); ?>
    		</nav><!-- #site-navigation -->
    	<?php endif; ?>

    *Note: I simply copied the nag div form the header and pasted it in the php if statement and changed class names for styling

    Then a page-sideNav.php template :

    get_header('header-noNav'); ?>
    	<div id="primary" class="site-content">
    		<div id="content" role="main">
    			<?php while ( have_posts() ) : the_post(); ?>
    				<?php get_template_part( 'content', 'page' ); ?>
    				<?php comments_template( '', true ); ?>
    			<?php endwhile; // end of the loop. ?>
    		</div><!-- #content -->
    	</div><!-- #primary -->
    <?php get_sidebar('sidebar-5'); ?>
    <?php get_footer(); ?>

    I have only applied this template to one page that is not published, just as a test. There is a break in all this that has disrupted the entire site, as in totally blank page. I do not have the experience to find it. I think I am on the right path and pretty sure there is an error in the functions because when I comment the register_sidebar array out, it shows back up, just not the way it is supposed to. So, you will actually see content, rather than a blank page. (On a side note, the get_header(‘header-noNav’) isn’t working either, I got that from Codex).

    I only have this template attached to one draft page for testing so this is the only way to see it.

    I do understand how its done, its the details that are eluding me. I am one of those show-me-don’t-tell-me people. Very A-B-C outline is best for my little head! Ha ha!

    Thank you so much for your time! Have a good one!!
    Lisa l;o)

  • The topic ‘Steps to Moving Primary Menu to New Sidebar Breaking in Code’ is closed to new replies.