WordPress导航菜单页脚和标题

时间:2017-12-11 11:26:26

标签: php wordpress

我是WordPress的新手,目前正在使用它。我的导航菜单出了问题。我的页眉和页脚上假设的不同菜单集是相同的。会出现什么问题?

这是我的代码: header.php的



<!DOCTYPE html>
<html <?php language_attributes(); ?>>
		<head>
			<meta charset="<?php bloginfo('charset');?>">
			<meta charset="viewport" content="width=device-width">
			<title><?php bloginfo('name'); ?></title>
			<?php wp_head(); ?>
		</head>
		
<body <?php body_class(); ?>>

	<div class="container">

	<!-- site-header -->
	<header class="site-header">
		<h1><a href="<?php echo home_url(); ?>"><?php bloginfo('name'); ?></a></h1>
		<h5><?php bloginfo('description'); ?></h5>

		<nav class="site-nav">
			<?php
				$args = array(
					'theme-location' => 'primary'
				);
			?>
			<?php wp_nav_menu(  $args ); ?>
		</nav>
	</header><!-- /site-header -->
&#13;
&#13;
&#13;

for footer.php

&#13;
&#13;
	<footer class="site-footer">
		<nav class="site-nav">
			<?php
				$args = array(
					'theme-location' => 'footer'
				);
			?>
			<?php wp_nav_menu(  $args ); ?>
		</nav>

		<p><?php bloginfo('name'); ?> - &copy; <?php echo date('Y'); ?></p>

	</footer>


</div> <!-- container -->


<?php wp_footer(); ?>
</body>
</html>
&#13;
&#13;
&#13;

for functions.php

&#13;
&#13;
<?php

function WordpressSample_resources() {

	wp_enqueue_style('style', get_stylesheet_uri());
}

add_action('wp_enqueue_scripts','WordpressSample_resources');

//Navigation Menus
register_nav_menus(array(
	'primary' => __( 'Primary Menu'),
	'footer' => __( 'Footer Menu'),
));
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

页脚和标题的WordPress导航菜单

在header.php文件中添加以下代码。

    <!DOCTYPE html>
<html <?php language_attributes(); ?>>
        <head>
            <meta charset="<?php bloginfo('charset');?>">
            <meta charset="viewport" content="width=device-width">
            <title><?php bloginfo('name'); ?></title>
            <?php wp_head(); ?>
        </head>

<body <?php body_class(); ?>>

    <div class="container">

    <!-- site-header -->
    <header class="site-header">
        <h1><a href="<?php echo home_url(); ?>"><?php bloginfo('name'); ?></a></h1>
        <h5><?php bloginfo('description'); ?></h5>

        <nav class="site-nav">
            <?php
            $header_menu_defaults = array(
                'theme_location'  => '',
                'menu'            => 'Primary Menu',
                'container'       => '',
                'container_class' => '',
                'container_id'    => '',
                'menu_class'      => '',
                'menu_id'         => '',
                'echo'            => true,
                'fallback_cb'     => 'wp_page_menu',
                'before'          => '',
                'after'           => '',
                'link_before'     => '',
                'link_after'      => '',
                'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>',
                'depth'           => 0,
                'walker'         => ''
            );
            wp_nav_menu( $header_menu_defaults );
        ?>
        </nav>
    </header><!-- /site-header -->

在footer.php文件中添加以下代码。

<footer class="site-footer">
    <nav class="site-nav">
         <?php
        $footer_menu_defaults = array(
            'theme_location'  => '',
            'menu'            => 'Footer Menu',
            'container'       => '',
            'container_class' => '',
            'container_id'    => '',
            'menu_class'      => '',
            'menu_id'         => '',
            'echo'            => true,
            'fallback_cb'     => 'wp_page_menu',
            'before'          => '',
            'after'           => '',
            'link_before'     => '',
            'link_after'      => '',
            'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>',
            'depth'           => 0,
            'walker'         => ''
        );
        wp_nav_menu( $footer_menu_defaults );
    ?>
    </nav>

    <p><?php bloginfo('name'); ?> - &copy; <?php echo date('Y'); ?></p>

</footer>