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.

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

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用