在Wordpress中创建自己的页脚菜单?

时间:2015-04-26 12:37:42

标签: php html wordpress

我的Wordpress-Page中有两个菜单叫做

Mainmenu(Primary Menu)
Footer

我联系了" Mainmenu"到网站的标题。我希望Wordpresspage的页脚看起来与标题完全一样,唯一的区别应该是它中的链接。它不应该来自" Mainmenu",而是来自名为" Footer"的菜单。标题的功能如下所示:

echo '<nav id="rtp-primary-menu" role="navigation" class="rtp-nav-wrapper' . apply_filters( 'rtp_mobile_nav_support', ' rtp-mobile-nav' ) . '">';
rtp_hook_begin_primary_menu();

/* Call wp_nav_menu() for Wordpress Navigaton with fallback wp_list_pages() if menu not set in admin panel */
if ( function_exists( 'wp_nav_menu' ) && has_nav_menu( 'primary' ) ) {
    wp_nav_menu( array( 'container' => '', 'menu_class' => 'menu rtp-nav-container clearfix', 'menu_id' => 'rtp-nav-menu', 'theme_location' => 'primary', 'depth' => apply_filters( 'rtp_nav_menu_depth', 4 ) ) );
} else {
    echo '<ul id="rtp-nav-menu" class="menu rtp-nav-container clearfix">';
    wp_list_pages( array( 'title_li' => '', 'sort_column' => 'menu_order', 'number' => '5', 'depth' => apply_filters( 'rtp_nav_menu_depth', 4 ) ) );
    echo '</ul>';
}

rtp_hook_end_primary_menu();
echo '</nav>';

我使用的主题是rtPanel。任何人都可以告诉我,我只是可以改变这个功能的方式,它将从名为&#34; Footer&#34;的菜单中加载其内容。而不是来自主菜单,这是&#34; Mainmenu&#34;?

请不要担心CSS和一切,我会照顾这个。我现在真的只想要改变这个功能来加载&#34;页脚&#34; -Menu而不是主菜单(Mainmenu)。

作为附件如何在菜单中显示:

enter image description here

非常感谢你!

1 个答案:

答案 0 :(得分:1)

这很简单,事实上当你开始开发wordpress主题时,这可能是你需要学习的第一个项目之一。

您需要为页脚区域注册菜单位置。您可以在codex

中了解详情
 register_nav_menu( 'footer', __( 'Footer Menu', 'theme-slug' ) );

这将为您注册菜单。由于您已经拥有菜单位置,因此只需找到位置参数。我们将在以下代码中使用它。现在假设它的页脚&#39;像上面那样。根据您引用的代码显示页脚菜单的代码 -

echo '<nav id="rtp-primary-menu" role="navigation" class="rtp-nav-wrapper' . apply_filters( 'rtp_mobile_nav_support', ' rtp-mobile-nav' ) . '">';
//rtp_hook_begin_primary_menu(); // we better disable this hook as it intends for the header primary menu

/* Call wp_nav_menu() for Wordpress Navigaton with fallback wp_list_pages() if menu not set in admin panel */
if ( function_exists( 'wp_nav_menu' ) ) {
    wp_nav_menu( array( 'container' => '', 'menu_class' => 'menu rtp-nav-container clearfix', 'menu_id' => 'rtp-nav-menu', 'theme_location' => 'footer', 'depth' => apply_filters( 'rtp_nav_menu_depth', 4 ) ) );
} else {
    echo '<ul id="rtp-nav-menu" class="menu rtp-nav-container clearfix">';
    wp_list_pages( array( 'title_li' => '', 'sort_column' => 'menu_order', 'number' => '5', 'depth' => apply_filters( 'rtp_nav_menu_depth', 4 ) ) );
    echo '</ul>';
}

//rtp_hook_end_primary_menu(); // we better disable this hook as it intends for the header primary menu
echo '</nav>';

请注意theme_location函数中的wp_nav_menu()参数?这是为了让你正确使用菜单而进行的。

现在玩CSS,你可能会得到你想要的东西。

希望这对你有所帮助。