【问题标题】:WordPress Navigation Menus for footer and header页脚和页眉的 WordPress 导航菜单
【发布时间】:2017-12-11 11:26:26
【问题描述】:

我是 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 -->

对于footer.php

	<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>

对于functions.php

<?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'),
));

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    页脚和页眉的 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-04
      • 1970-01-01
      • 1970-01-01
      • 2013-11-30
      • 2020-08-02
      • 2014-09-29
      • 1970-01-01
      相关资源
      最近更新 更多