0

我第一次制作自己的自定义 wordpress 主题,但在尝试注册菜单时遇到了障碍。

我在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 中看不到要添加项目的菜单。这是我在其中注册它们的功能:

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

这是我使用它的方式:

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

而是显示的是一个 ul 标记,其中包含 Home 后跟我的页面。

看到我在 wp-admin 中看不到菜单,我认为寄存器以某种方式失败。

有人可以帮忙吗?

4

1 回答 1

0

这是因为您还没有指定菜单。

为菜单设置代码后,您应该转到仪表板并从那里创建一个菜单 ( Appearance-> Menu)。或者你也没有看到这个菜单?您的代码中有一个迷路endif;,您可以发布整个代码吗?

输入菜单名称,将所需项目添加到菜单,然后单击Create menu。查看外观菜单屏幕以了解其工作原理。

于 2013-02-07T05:21:56.593 回答