我不是程序员,但我通常可以在阅读代码时完成这样的工作。
我有一个主题叫做无限,它只支持一个菜单。我知道如何做CSS等,但我找不到我会如何第二个菜单。事实上,它不必是自定义菜单,只需页面即可。谁能告诉我怎么做?下面是代码摘录,用于加载菜单:
<div class="container_main">
<div class="container_12_head">
<?php get_template_part( \'custom\', \'header\' ); ?>
<div class="clear"></div>
</div>
<div class="container_head_menu_wrap">
<div class="container_12_head">
<?php get_template_part( \'primary\', \'menu\' ); ?>
<div class="clear"></div>
</div>
</div>
此代码位于标题中。php。我搜索主菜单。php并在其中找到以下内容:
<?php
/** Primary Menu Callback */
function infinity_primary_menu_cb() {
wp_page_menu();
}
?>
<div class="grid_8 alpha">
<div class="menu1">
<div class="menu1-data">
<?php
if ( has_nav_menu( \'infinity-primary-menu\' ) ):
$args = array(
\'container\' => \'div\',
\'container_class\' => \'primary-container\',
\'theme_location\' => \'infinity-primary-menu\',
\'menu_class\' => \'sf-menu1\',
\'depth\' => 0,
\'fallback_cb\' => \'infinity_primary_menu_cb\'
);
wp_nav_menu( $args );
else:
infinity_primary_menu_cb();
endif;
?>
<div class="clear"></div>
</div>
</div> <!-- end .menu1 -->
</div>
有什么帮助吗?
编辑:更新。粘贴在下面的功能页
<?php
/** Load the Core Files */
require_once( trailingslashit( get_template_directory() ) . \'lib/init.php\' );
new Infinity();
/** Do theme setup on the \'after_setup_theme\' hook. */
add_action( \'after_setup_theme\', \'infinity_theme_setup\' );
/** Theme setup function. */
function infinity_theme_setup() {
/** Add theme support for core framework features. */
add_theme_support( \'infinity-core-menus\', array( \'infinity-primary-menu\' ) );
add_theme_support( \'infinity-core-sidebars\', array( \'infinity-primary-sidebar\' ) );
add_theme_support( \'infinity-core-featured-image\' );
add_theme_support( \'infinity-core-custom-header\' );
/** Add theme support for WordPress features. */
add_theme_support( \'automatic-feed-links\' );
add_theme_support( \'custom-background\', array( \'default-color\' => \'fafafa\' ) );
/** Set content width. */
infinity_set_content_width( 600 );
/** Add custom image sizes. */
add_action( \'init\', \'infinity_add_image_sizes\' );
}
/** Adds custom image sizes */
function infinity_add_image_sizes() {
add_image_size( \'featured\', 200, 200, true );
}
?>
下面的菜单代码
function infinity_register_menus() {
/** Get theme-supported menus. */
$menus = get_theme_support( \'infinity-core-menus\' );
/** If there is no array of menus IDs, return. */
if ( !is_array( $menus[0] ) ) {
return;
}
/* Register the \'primary\' menu. */
if ( in_array( \'infinity-primary-menu\', $menus[0] ) ) {
register_nav_menu( \'infinity-primary-menu\', __( \'Infinity Primary Menu\', \'infinity\' ) );
}
最合适的回答,由SO网友:Sagive 整理而成
向wordpress主题添加自定义菜单位置相当简单
这通常是这样做的:
1. Announcing the desired menu positions (in function.php):
add_action( \'init\', \'register_my_menus\' );
function register_my_menus() {
register_nav_menus(
array(
\'first-menu\' => __( \'First Menu\' ),
\'second-menu\' => __( \'Second Menu\' ),
\'third-menu\' => __( \'Third Menu\' )
)
);
}
。
2. Embedding them in desired place in your theme:
<?php wp_nav_menu( array( \'theme_location\' => \'first-menu\' ) ); ?>
。
在您的情况下&;由于您已经有一个自定义菜单位置,因此首先需要在函数中找到它。php,其中定义了当前菜单,并添加另一个菜单,如上面的示例所示。
希望这有帮助,萨吉夫。
已编辑(替换菜单代码中的现有代码):
function infinity_register_menus() {
/** Get theme-supported menus. */
$menus = get_theme_support( \'infinity-core-menus\' );
/** If there is no array of menus IDs, return. */
if ( !is_array( $menus[0] ) ) {
return;
}
/* Register the \'primary\' menu. */
if ( in_array( \'infinity-primary-menu\', $menus[0] ) ) {
register_nav_menu(
array(
\'infinity-primary-menu\' => __( \'Infinity Primary Menu\', \'infinity\' ),
\'secondary-menu\' => __( \'Secondary Primary Menu\', \'infinity\' )
)
);
}
}