dongqiabei7682 2013-02-07 04:27
浏览 49
已采纳

Wordpress不允许我们注册菜单

I'm making my own custom wordpress theme for the first time and I've hit a snag when trying to register menus.

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. 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.

seeing as i can't see the menus in wp-admin i assume the register is failing somehow.

Can anybody help?

  • 写回答

1条回答 默认 最新

  • duanposhi3641 2013-02-07 05:21
    关注

    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). Or you are not seeing this menu either? There's a stray 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. Have a look at Appearance Menus Screen to understand how it works.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路