• Resolved graham333

    (@graham333)


    Hope this is in the right place.

    I am trying do this without knowing if it’s possible (as usual haha) but what I have done so far seems to work up to a point.

    I’m using the 2012 theme (with child) what I want to do is put the standard navbar menu on the home page template ONLY.

    So taking the bull by the horns, I took the navbar code from the header.php file and pasted it into the page-templates/front-page.php and thought that would do the trick (poor fool that I am)

    Although it has worked somewhat in that it has put all the navigation links in a vertical list on the front-page.php but…

    … unlike me I’m sure you coders will know what the problem is going to be viz…

    I have lost the horizontal style from the css somewhere along the way and of course the menu Javascript is not working either.

    Yet again I have no idea how to put this right, if some valiant soul can please help me get this working correctly I will be eternally grateful.
    Apart from jumping off a bridge, what are my next steps?

    ======================

    This is the code snippet from the header.php I pasted in

    <nav id="site-navigation" class="main-navigation" role="navigation">
    			<button class="menu-toggle"><?php _e( 'Menu', 'twentytwelve' ); ?></button>
    			<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' => 'nav-menu' ) ); ?>
    		</nav><!-- #site-navigation -->

    this is the code that is in the front page.php template to save you lookinh it up.

    <?php
    /**
     * Template Name: Front Page Template
     *
     * Description: A page template that provides a key component of WordPress as a CMS
     * by meeting the need for a carefully crafted introductory page. The front page template
     * in Twenty Twelve consists of a page content area for adding text, images, video --
     * anything you'd like -- followed by front-page-only widgets in one or two columns.
     *
     * @package WordPress
     * @subpackage Twenty_Twelve
     * @since Twenty Twelve 1.0
     */
    
    get_header(); ?>
    
    	<div id="primary" class="site-content">
    		<div id="content" role="main">
    
    			<?php while ( have_posts() ) : the_post(); ?>
    				<?php if ( has_post_thumbnail() ) : ?>
    					<div class="entry-page-image">
    						<?php the_post_thumbnail(); ?>
    					</div><!-- .entry-page-image -->
    				<?php endif; ?>
    
    				<?php get_template_part( 'content', 'page' ); ?>
    
    			<?php endwhile; // end of the loop. ?>
    
    		</div><!-- #content -->
    	</div><!-- #primary -->
    
    <?php get_sidebar( 'front' ); ?>
    <?php get_footer(); ?>

    and this is where I have pasted the header code into front page.php

    get_header(); ?>
    
    <script src="<?php echo get_template_directory_uri(); ?>/js/html5.js" type="text/javascript"></script>
    
    <?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) ); ?>
    
    <nav id="site-navigation" class="main-navigation" role="navigation">
    			<button class="menu-toggle"><?php _e( 'Menu', 'twentytwelve' ); ?></button>
    			<a class="assistive-text" href="#content" title="<?php esc_attr_e( 'Skip to content', 'twentytwelve' ); ?>"></nav><!-- #site-navigation -->
    
    <?php _e( 'Skip to content', 'twentytwelve' ); ?></a>
    </nav><!-- #site-navigation -->
    
    	<div id="primary" class="site-content">
    		<div id="content" role="main">
    
    			<?php while ( have_posts() ) : the_post(); ?>
    				<?php if ( has_post_thumbnail() ) : ?>
    					<div class="entry-page-image">
    						<?php the_post_thumbnail(); ?>
    					</div><!-- .entry-page-image -->
    				<?php endif; ?>
    
    				<?php get_template_part( 'content', 'page' ); ?>
    
    			<?php endwhile; // end of the loop. ?>
    
    		</div><!-- #content -->
    	</div><!-- #primary -->

    Standing by, but not holding my breath in case I have posted in the wrong place ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi Graham, instead of removing the navigation snippet from the header, try this

    • put the navigation snippet back where it was before, in your header.php file
    • add an “if” condition in header.php to show the navigation bar only when you’re visiting the front page, using the “is_front_page()” function

    Your code should look like this

    <?php if ( is_front_page() ) : ?>
    <nav id="site-navigation" class="main-navigation" role="navigation">
    			<button class="menu-toggle"><?php _e( 'Menu', 'twentytwelve' ); ?></button>
    			<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' => 'nav-menu' ) ); ?>
    </nav><!-- #site-navigation -->
    <?php endif; ?>

    As you see I added

    <?php if ( is_front_page() ) : ?>

    at the beginning of the snippet and

    <?php endif; ?>

    at the end of the snippet.

    You can find more information about how “is_front_page()” work here
    https://codex.www.ads-software.com/Function_Reference/is_front_page

    Hope it helps:)

    Thread Starter graham333

    (@graham333)

    @ fedeandri

    Thanks very much, that’s exactly what I needed.

    Have and great weekend and Merry Christmas! ??

    Glad to hear that Graham!
    If you don’t mind, please mark the topic as “resolved”.

    Have a great weekend and Merry Christmas to you too:)

    Thread Starter graham333

    (@graham333)

    Wilco ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Adding Navbar to Page.php’ is closed to new replies.