简体   繁体   English

WordPress不允许我们注册菜单

[英]Wordpress won't allow we to register menus

I'm making my own custom wordpress theme for the first time and I've hit a snag when trying to register menus. 我第一次制作自己的自定义wordpress主题,尝试注册菜单时遇到了障碍。

I've followed a tutorial to build the theme at http://themeshaper.com/2012/10/22/the-themeshaper-wordpress-theme-tutorial-2nd-edition/ and looked it up on http://justintadlock.com/archives/2010/06/01/goodbye-headaches-hello-menus but no matter what i do the code that registers the menu won't work as I don't see the menu to add items to in wp-admin. 我已按照http://themeshaper.com/2012/10/22/the-themeshaper-wordpress-theme-tutorial-2nd-edition/上的教程构建主题,并在http:// justintadlock上进行了查找。 com / archives / 2010/06/01 / goodbye-headaches-hello-menus,但是无论我做什么注册菜单的代码都无法正常工作,因为我看不到菜单在wp-admin中添加项目。 Here's the function I register them in: 这是我在其中注册的功能:

if ( ! function_exists( 'eastmids_setup' ) ):
/**
 * Sets up theme defaults and registers support for various WordPress features.
 *
 * Note that this function is hooked into the after_setup_theme hook, which runs
 * before the init hook. The init hook is too late for some features, such as indicating
 * support post thumbnails.
 *
 * @since eastmids 1.0
 */
function eastmids_setup() {

/**
 * Custom template tags for this theme.
 */
require( get_template_directory() . '/inc/template-tags.php' );

/**
 * Custom functions that act independently of the theme templates
 */
require( get_template_directory() . '/inc/tweaks.php' );

/**
 * Make theme available for translation
 * Translations can be filed in the /languages/ directory
 * If you're building a theme based on eastmids, use a find and replace
 * to change 'eastmids' to the name of your theme in all the template files
 */
load_theme_textdomain( 'eastmids', get_template_directory() . '/languages' );

/**
 * Add default posts and comments RSS feed links to head
 */
add_theme_support( 'automatic-feed-links' );

/**
 * Enable support for the Aside Post Format
 */
add_theme_support( 'post-formats', array( 'aside' ) );

/**
 * This theme uses wp_nav_menu() in one location.
 */
register_nav_menus( array(
    'primary' => __( 'Primary Menu' ),
) );
}
endif; // eastmids_setup
add_action( 'after_setup_theme', 'eastmids_setup' );

And here is how I use it: 这是我的用法:

<nav role="navigation" class="site-navigation main-navigation">
     <?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>
</nav>

What is displayed instead is an ul tag containing Home followed by my pages. 而是显示一个ul标记,其中包含Home和其后的页面。

seeing as i can't see the menus in wp-admin i assume the register is failing somehow. 看到我看不到wp-admin中的菜单,我认为寄存器以某种方式失败了。

Can anybody help? 有人可以帮忙吗?

It is because you haven't specified a menu yet. 这是因为您尚未指定菜单。

After you've set up your codes for the menu, you should go to the dashboard and create a menu from there ( Appearance -> Menu ). 设置菜单代码后,应转到仪表板并从此处创建菜单( Appearance -> Menu )。 Or you are not seeing this menu either? 还是您也没有看到此菜单? There's a stray endif; 有一个流浪的endif; in your code, could you post the entire code please? 在您的代码中,您可以张贴整个代码吗?

Enter the menu name, add required items to the menu and click on Create menu . 输入菜单名称,将必需的项目添加到菜单,然后单击“ Create menu Have a look at Appearance Menus Screen to understand how it works. 查看外观菜单屏幕以了解其工作原理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM