二级菜单未显示在WordPress页脚中

时间:2018-10-10 16:15:05

标签: php wordpress wordpress-theming

我是一个尝试创建自己的wordpress主题的初学者。

我有两个导航菜单,其中一个用于页眉,一个用于页脚,但第二个菜单不显示页脚。我的代码当前如下所示。

-Functions.php

function base_theme_setup(){

 add_theme_support('menus');

 register_nav_menu('primary','Primary Header Navigation');
 register_nav_menu('secondary','Secondary Footer Navigation');

}

add_action ('init', 'base_theme_setup');

-footer.php

<footer>
<?php wp_nav_menu(array('theme_location'=>'secondary')); ?>

</footer>

<?php wp_footer (); ?>

</body>
</html>

1 个答案:

答案 0 :(得分:1)

设法解决。

在index.php的底部有一些无用的未删除代码。一旦删除,问题就消失了。

从这开始

<?php

 if( have_posts() ):

    while( have_posts() ): the_post(); ?>

       <h3><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
</h3>
       <div class="thumbnail-img"><?php the_post_thumbnail('large'); ?></div>
       <p><?php the_content(); ?></p>
       <small>Posted on: <?php the_time('F j,Y'); ?> at <?php the_time('g:i a'); ?>, in <?php the_category(); ?></small>
       <hr>

<?php   endwhile;

 endif;

 ?>

<?php

            while ( have_posts() ) : the_post();

                get_template_part( 'content', get_post_format() );

            endwhile; 
?>

<?php get_footer();?>

对此

<?php 

 if( have_posts() ):

    while( have_posts() ): the_post(); ?>

      <h3><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>

      <?php the_post_thumbnail('large'); ?>

      <p><?php the_content(); ?></p>

      <small>Posted on: <?php the_time('F j,Y'); ?> at <?php the_time('g:i a'); ?>, in <?php the_category();?></small>

      <hr>

<?php   endwhile;

 endif;

 ?>
 <?php get_footer();?>

感谢大家的提示!