【问题标题】:Secondary menu not showing up in wordpress footer二级菜单未显示在 wordpress 页脚中
【发布时间】:2018-10-11 14:28:13
【问题描述】:

我是一个尝试创建自己的 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>

【问题讨论】:

  • 听起来不太简单,但您是否在 WordPress 中选择了二级菜单并为其分配了菜单项?
  • 是的,我有。这一切在后端看起来都很好,只是没有出现在网站上。
  • 尝试将init 更改为after_setup_theme
  • 之前给过但没有效果:(
  • 转到相关站点并按 Ctrl+F5。

标签: php wordpress wordpress-theming


【解决方案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();?>

感谢大家的提示!

【讨论】:

  • 很高兴听到您解决了问题并在此处发布了您的解决方案。 :-) 重申我之前的评论,将init 更改为after_setup_theme 作为良好做法,并确保您以后不会遇到任何问题。祝您的主题发展/学习曲线好运!
  • 也许这会产生一些错误。在开发过程中总是使用define('WP_DEBUG', true);在 wp-config.php 文件中
  • @MahfuzulHasan:很好的提示。有时,基础知识可能会被忽略! :-)
  • 感谢您的所有提示!
猜你喜欢
  • 1970-01-01
  • 2022-01-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多