[wordpress插件] Automatic Submenu for Categories & Pages分类和页面的自动子菜单

wordpress 插件 文章 2020-02-25 14:50 536 0 全屏看文

AI助手支持GPT4.0

评分
60
描述

Ever wanted to be able to automatically have category and pages children automatically added to your menus?

是否曾经希望能够自动将子类别和页面自动添加到菜单中?

I’m sure I did and was disappointed to not find something that dead simple that works and doesn’t mess up with the theme or other plugins.

我确定我确实做到了,并且很失望,没有找到可以正常工作且不会弄乱主题或其他插件的东西。

Now bear with me on this one as it is my first WP plugin for like a decade and the first ever to be shared so i kept it quite basic.

现在就与我同在,因为这是我十年来的第一个WP插件,也是有史以来第一个被共享的插件,因此我保持了相当基本的意思。

How it works:

工作原理:

    • On each menu item that is either a category or a page you get an option to automatically append their children as a submenu
    • 在属于类别或页面的每个菜单项上,您都可以选择自动将其子项附加为子菜单

    • You get to decide how many children to show and how they’re gonna be ordered (Title or Date)
    • 您可以决定要显示多少个孩子以及如何订购(标题或日期)

    • And that’s it, all you have to do is create content and never worry about your menu again.
    • 就是这样,您要做的就是创建内容,而不必担心菜单再次出现。

    • As promised, it doesn’t mess with the theme or other plugins, it just injects the children found in the corresponding place of the nav menu array when that is triggered in the frontend
    • 如所承诺的那样,它不会与主题或其他插件混淆,它只是将在前端触发的导航菜单数组的相应位置中找到的子项注入

    Code hacks

    代码黑客

    There is no settings page for the plugin but you can change a couple default behaviours from the code itself

    该插件没有设置页面,但是您可以从代码本身更改一些默认行为

    Changing the default maximum children number when the field is empty

    更改该字段为空时的默认最大子代人数

    $item->automatic_max = 5;

      $ item-> automatic_max = 5;

    just change the number at line 220

    只需更改第220行的数字

    Bring only direct children of Pages and not all ascendants

    仅带Pages的直系子孙,而不带所有子孙

    $children = get_pages( array( 'child_of' => $item->object_id, 'number' => $item->automatic_max, 'sort_column' => 'post_'.$ordering[0],

      $ children = get_pages(array('child_of'=> $ item-> object_id,'number'=> $ item-> automatic_max,'sort_column'=>'post _'。$ ordering [0], 

    'sort_order' => strtoupper( $ordering[1] ) ) );

    'sort_order'=> strtoupper($ ordering [1])));

    just change 'child_of' to 'parent' at line 226

    只需在第226行将“ child_of”更改为“ parent”

    Upcoming Features:

    即将推出的功能:

    Due to lack of time i will implement the following features upon demand.

    由于时间不足,我将根据需要实现以下功能。

    Please post your requests in the forum.

    请在论坛中发布您的请求。

      • Settings Page
      • 设置页面

      • Submenu items ordering
      • 子菜单项订购

      • Support for custom post types and taxonomies
      • 支持自定义帖子类型和分类法

      Credits:

      积分:

        • I have used the menu walker created by zviryatko (https://plugins.trac.wordpress.org/browser/menu-image/trunk/menu-image.php)
        • 我使用了zviryatko(https://plugins.trac.wordpress.org/browser/menu-image/trunk/menu-image.php)创建的菜单浏览器

安装步骤

Plain and simple

简单明了

    1. Upload the plugin folder to the /wp-content/plugins/ directory, or install the plugin through the WordPress plugins screen directly.
    2. 将插件文件夹上传到 / wp-content / plugins / 目录,或直接通过WordPress插件屏幕安装插件。

    3. Activate the plugin through the ‘Plugins’ screen in WordPress
    4. 通过WordPress中的“插件”屏幕激活插件

    5. Go to Appearance->Menu and config each menu item as you like
    6. 转到“外观”->“菜单”并根据需要配置每个菜单项

下载地址
https://downloads.wordpress.org/plugin/automatic-submenu.zip
-EOF-

AI助手支持GPT4.0