[WordPress] 外掛分享: Menu Item Types

首頁外掛目錄 › Menu Item Types
WordPress 外掛 Menu Item Types 的封面圖片
80+
安裝啟用
★★★★★
5/5 分(2 則評價)
167 天前
最後更新
0%
問題解決
WordPress 5.8+ PHP 8.0+ v1.7 上架:2021-10-06

內容簡介

Menu Item Types 讓您在導覽選單中輕鬆添加鏈結、標題、沒有 URL 的選項、段落或圖像等存檔頁面。
您還可以輕鬆覆蓋模板和/或創建自己的自定義元素。

篩選器
// Disable Post Type Archive Metabox
add_filter( 'mitypes_has_post_type_archive_metabox', '__return_false' ) ;

// Disable Buildin Item types
add_filter( 'mitypes_has_buildin_item_types', '__return_false' ) ;

// Mix Buildin and Plugin Item types in the metabox
add_filter( 'mitypes_mix_metabox_item_types', '__return_true' ) ;

// Filter Supported Item types
add_filter( 'mitypes_supported_types', function(){ return ['image']; } );

Menu Item Types 可以擴充

已經有其他額外的外掛程式。
您還可以像這些外掛程式一樣創建自己的元素:

Menu Item Types - 按鈕
Menu Item Types - 操作

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.7) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Menu Item Types」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

Menu Item Types makes it easy to add links to your archive pages, titles, items without URL, paragraphs or images to your navigation menus.
You can also easily override the templates and/or create your own custom elements.

Create your own item type
You need to declare your new type in, functions.php, a plugin, child theme, or your custom theme like this :
function register_my_custom_type(){

$args = array(
'slug' => "my-custom-type",
'label' => __( 'My Custom Type', 'my-custom-type' ),
'render' => 'path/to/render/my-custom-render.php',
);

mitypes_register_type( $args );
}
add_action( 'mitypes_init', 'register_my_custom_type' );

You can do more than that on $args.
$args = array(
'slug' => "my-custom-type",
'label' => __( 'My Custom Type', 'my-custom-type' ),
'render' => 'path/to/my-custom-type-render.php',

// Link your custom icon
'icon' => 'https://url-to-icon-file.svg',

// Return ACF Group field array
'field-group' => [
'key' => 'uniq_key',
'title' => 'Group Title',
'fields => [
...
],
'location' => [
[
[
'param' => 'mitypes',
'operator' => '==',
'value' => 'my-custom-type',
],
],
],

],

// Use callback for customize your item
// you can add filter on 'mitypes_nav_menu_link_attributes' if you need
'callback' => function(){ ... }
);

And finally, you can work in the render with some variables.
You have two variables available:
// $item is the WP_Post of the menu item, with which you can, for example, retrieve custom field data.

$id = get_field( 'acf-slug', $item->ID ) ;

// $args is an object containing the complete configuration of the wp_nav_menu() call,
// including the current menu (WP_Term), classes, IDs, wrappers, depth, walker, menu location, etc.
// More info : https://developer.wordpress.org/reference/functions/wp_nav_menu/

There are already additional plugins.
You can also create your own elements like these plugins do:

Menu Item Types — Button
Menu Item Types — Action

Customize the plugin
// Disable Post Type Archive Metabox
add_filter( 'mitypes_has_post_type_archive_metabox', '__return_false' ) ;

// Disable Buildin Item types
add_filter( 'mitypes_has_buildin_item_types', '__return_false' ) ;

// Mix Buildin and Plugin Item types in the metabox
add_filter( 'mitypes_mix_metabox_item_types', '__return_true' ) ;

// Filter Supported Item types
add_filter( 'mitypes_supported_types', function(){ return ['image']; } );

// Disable Nav Item Icons
add_filter( 'mitypes_nav_menu_items_has_icons', '__return_false' ) ;

延伸相關外掛

文章
Filter
Apply Filters
Mastodon