2013-02-07 36 views
0

我第一次製作我自己的自定義WordPress主題,並且在嘗試註冊菜單時遇到了麻煩。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標籤。

看到因爲我無法看到wp-admin中的菜單我假設註冊表失敗。

任何人都可以幫忙嗎?

回答

0

這是因爲你還沒有指定菜單。

在爲菜單設置了代碼後,您應該轉到儀表板並從那裏創建一個菜單(Appearance - >Menu)。或者你還沒有看到這個菜單?你的代碼中有一個流浪的endif;,你可以發佈整個代碼嗎?

輸入菜單名稱,將所需的項目添加到菜單並點擊Create menu。看看Appearance Menus Screen瞭解它是如何工作的。

+0

啊我看到了,我沒有意識到'主'名是wp_nav_menu調用位置的句柄。 我認爲這是當我註冊菜單時,它會顯示爲一個菜單添加到wp-admin的項目,但是當我去那裏創建一個新的菜單,我發現你的意思是在「主題位置」 –