[英]wordpress custom menu with page thumbnail
我正在嘗試獲得一個包含少量鏈接的菜單,並顯示他們的/鏈接/頁面特色圖像。 以下是我的functions.php代碼。
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個鏈接及其圖像。
謝謝
這應該在你的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菜單工作所必需的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.