2016-08-17 36 views
1

我想獲得一個菜單,有幾個鏈接,並顯示他們的/鏈接/頁面精選圖像。以下是我的functions.php代碼。WordPress的自定義菜單與頁面縮略圖

function register_my_menus() { 
    register_nav_menus(
    array(
     'main-menu' => __('Main Menu'), 
     'useful-links' => __('Userful Links') 
    ) 
); 
} 
add_action('init', 'register_my_menus'); 

這就是我在頁面中調用它的地方。

<?php wp_nav_menu(array('theme_location' => 'useful-links', 'sort_column' => 'menu_order', 'container_class' => 'useful-links', 'menu'=>'Posts Menu')); ?> 

我知道一些東西缺失,但善意的建議。我的頁面外觀和感覺允許6個鏈接及其圖片。

謝謝

回答

0

這應該是在你的functions.php註冊WordPress的菜單。

if (!function_exists('wp_basicTemplateSetup')) { 
    function wp_basicTemplateSetup() { 
     // Register the Main Menus into WordPress 
     register_nav_menus(array(
      'primary' => __('Main Menu', 'theme-name'), 
     )); 
    } 
} 
add_action('after_setup_theme', 'wp_basicTemplateSetup'); 

在您的主題中,菜單位於哪裏,您需要告訴菜單功能,查找哪個菜單。所以..:

// Variable that tells WordPress which menu to use, look at "Theme Location" 
// Put this variable either at the top of your theme, of right *before* the function wp_nav_menu 

$mainmenu = array(
    'theme_location' => 'primary', 
    'container' => false, 
    'menu_class' => 'some-menu-css-class', 
    'depth' => 2 
); 

// The WordPress menu function 
<?php wp_nav_menu($mainmenu); ?> 

這3個組件是讓你的WordPress菜單工作所必需的。

+0

有用的鏈接是執行第一個組件。我可以在主題的特定位置打電話給我的菜單。只想調用作爲後置圖像的錨的圖像。希望你能理解。 –

+0

ahh nope - 對不起 - 如果你想得到一個帖子的圖像(這可能是你的第一個鏈接或任何..然後你需要查詢WordPress的帖子,而不是菜單) – 2016-08-17 15:09:29

+0

http://stackoverflow.com/問題/ 26079190/add-featured-image-to-wp-nav-menu-items –