外观栏中缺少Wordpress菜单

时间:2017-08-30 06:05:00

标签: wordpress

我想从头开始制作自定义WordPress主题所以我删除了所有主题,现在外观栏中缺少菜单, 我尝试在add_theme_support( 'menus' );文件中添加functions.php代码,然后我的网页本身无法打开。

附件是供您参考的屏幕截图。

请帮助

enter image description here

enter image description here

3 个答案:

答案 0 :(得分:0)

functions.php

中使用此功能
register_nav_menus(
    array('header_menu' =>'This is Header Menu'));

显示此菜单使用此代码显示菜单

wp_nav_menu(array('theme_location'=>'header_menu','container'=>''));

答案 1 :(得分:0)

您需要使用register_nav_menus()动作挂钩中的after_setup_theme注册菜单。

请检查以下代码。它可以帮助您创建两种类型的菜单显示位置

function custom_theme_setup() {
    register_nav_menus( array(
            'primary' => esc_html__( 'Primary Menu', 'nepalbuzz' ),
            'footer'  => esc_html__( 'Footer Menu', 'nepalbuzz' ),
    ) );
}
add_action( 'after_setup_theme', 'custom_theme_setup' );
  

此代码转到您的自定义主题function.php文件

对于使用wp_nav_menu()功能的显示菜单。

if ( has_nav_menu( 'primary' ) ) {
    $args = array(
        'theme_location'    => 'primary',
        'menu_class'        => 'menu nepalbuzz-nav-menu',
        'container'         => false
    );
    wp_nav_menu( $args );
}
  

此代码转到您要显示菜单的自定义主题文件

答案 2 :(得分:0)

请使用register_nav_menus()

这样您就可以为主题创建自定义菜单。喜欢

select * from xmltable('//*' passing  xmltype ('
<item_content>
  <stimulus_reference>
    <table_wrapper>
      <table frame="all" colsep="1" rowsep="1" pgwide="0">
        <tgroup cols="3">
          <thead>
            <row>
              <entry />
              <entry align="center">Male</entry>
              <entry align="center">Female</entry>
            </row>
          </thead>
          <tbody>
            <row>
              <entry align="left">Juniors</entry>
              <entry align="right">12</entry>
              <entry align="right">3</entry>
            </row>
            <row>
              <entry align="left">Seniors</entry>
              <entry align="right">9</entry>
              <entry align="right">21</entry>
            </row>
          </tbody>
        </tgroup>
      </table>
    </table_wrapper>
    <rationale>This is a rationale paragraph</rationale>
  </stimulus_reference>
  <task>
    <item_stem>
      <stem_paragraph>The table above shows the distribution of students that attended a concert, by class and gender.</stem_paragraph>
    </item_stem>
    <item_response>
      <response_choices>
        <columnar_choice_list>
          <columns align="character" align_character="1">
            <choice_row numeric_identifier="1">
              CHROW1
              <choice_cell>3</choice_cell>
            </choice_row>
            <choice_row numeric_identifier="2">
              CHROW2
              <choice_cell>15</choice_cell>
            </choice_row>
            <choice_row numeric_identifier="3">
              CHROW3
              <choice_cell>2102</choice_cell>
            </choice_row>
            <choice_row numeric_identifier="4">
              CHROW4
              <choice_cell>321</choice_cell>
            </choice_row>
            ColumnsData
          </columns>
        </columnar_choice_list>
      </response_choices>
    </item_response>
  </task>
  <math_expression>1+2=3</math_expression>
</item_content>')
columns 
 node_name varchar2(100) path 'name()',
 node_value varchar2(100) path 'text()' 
)

之后通过“after_setup_theme”钩子添加菜单,如

function register_theme_menu() {
  register_nav_menu( 'primary', __( 'Primary Menu', 'theme-slug' ) );
}

完整的代码就像你的fuctions.php文件一样。

add_action( 'after_setup_theme', 'register_theme_menu' );

https://codex.wordpress.org/Function_Reference/register_nav_menu

获取完整信息