简体   繁体   English

如何为链接管理器创建自定义菜单以在Wordpress中的导航下显示

[英]How to create a Customized Menu for Link Manager to display under the Nav in Wordpress

Let me see if I can explain this correctly. 让我看看是否可以正确解释。

I have a wordpress blog setup, I have my main menu code in my header.php listed below. 我有一个wordpress博客设置,下面的header.php中有主菜单代码。

<?php wp_nav_menu( array( 'theme_location' => 'main-menu', 'menu_class' => 'nav' ) ); ?>

Now what I am looking for is the same type of menu but it will carry my Categories from the Links manager. 现在,我正在寻找的是相同类型的菜单,但它将带有“链接”管理器中的“我的类别”。 Currently what I am using is the code below but that only gives me the links. 目前,我正在使用的是下面的代码,但这只给了我链接。

<?php wp_list_bookmarks('title_li=&categorize=0'); ?>

Any help would be appreciated. 任何帮助,将不胜感激。

Are you trying to replace the links in your main menu? 您是否要替换主菜单中的链接? Or are you adding a 2nd menu for your cat links? 还是为猫链接添加第二个菜单?

If you are trying to replace the existing links in your main menu, you can do that by going to your dashboard > appearance > menus. 如果您要替换主菜单中的现有链接,可以通过转到仪表板>外观>菜单来实现。 Make sure you're editing the Main menu and simply remove the existing links and add new links found within the 'categories' dropdown option. 确保您正在编辑主菜单,只需删除现有链接并添加在“类别”下拉选项中找到的新链接。

You can add an additional menu by adding code to your functions file, building the menu within your dashboard (just as you would the main menu), and adding the new menu to your header template. 您可以通过以下方式添加其他菜单:在功能文件中添加代码,在仪表板中构建菜单(就像在主菜单中一样),然后将新菜单添加到标题模板中。

If you open your function.php file, you should find something like this: 如果打开function.php文件,则应该找到以下内容:

// This theme uses wp_nav_menu() for primary and footer links.
    register_nav_menus( array(
        'primary' => __( 'Primary Menu', 'YOURTHEMENAME' ),
        'footer' => __( 'Footer Links', 'YOURTHEMENAME' ),
    ) );

Modify it to add your new menu, ie: 对其进行修改以添加新菜单,即:

// This theme uses wp_nav_menu() for primary and footer links.
    register_nav_menus( array(
        'primary' => __( 'Primary Menu', 'YOURTHEMENAME' ),
        'mycatlinks' => __( 'Category Menu', 'YOURTHEMENAME' ),
        'footer' => __( 'Footer Links', 'YOURTHEMENAME' ),
    ) );

Don't miss any of those commas! 不要错过任何逗号!

Save your function file, go to the menu builder, and create a new menu. 保存功能文件,转到菜单生成器,然后创建一个新菜单。 Add the category links you want to include. 添加您要包括的类别链接。 Be sure to check the box for 'Category Menu' as the new menu location. 确保选中“类别菜单”框作为新菜单位置。 Save the menu. 保存菜单。

Now go to your header.php file and add the new menu: 现在转到您的header.php文件并添加新菜单:

<?php wp_nav_menu( array( 'theme_location' => 'mycatlinks' ) ); ?>

Save header.php, refresh your page, and you should see the new menu! 保存header.php,刷新页面,您应该会看到新菜单! The only thing bad about this method is that the menu will not automatically update as new categories are added - you'll have to go back and add them manually within the menu builder. 这种方法的唯一缺点是,添加新类别后菜单不会自动更新-您必须返回并在菜单构建器中手动添加它们。 But you shouldn't have too many categories anyway.... that's what tags are for! 但是无论如何,您不应有太多类别。...这就是标签的用途!

Hope this helps. 希望这可以帮助。 Have a good Friday! 祝你周五愉快!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM