[WordPress] 外掛分享: Custom Menu Fields

前言介紹

  • 這款 WordPress 外掛「Custom Menu Fields」是 2014-01-27 上架。 目前已經下架不再更新,不建議安裝使用。
  • 目前有 40 個安裝啟用數。
  • 上一次更新是 2021-09-20,距離現在已有 1322 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
  • 外掛最低要求 WordPress 3.5 以上版本才可以安裝。
  • 有 2 人給過評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

diddledani |

外掛標籤

api | menu | field | fields |

內容簡介

這個外掛提供一個 API,讓網站開發人員能在預設的選單編輯器上增加自訂欄位。

初始化範例
add_action('init', 'menu_excerpt__add_menu_field');
function menu_excerpt__add_menu_field() {
if (!is_callable('bh_add_custom_menu_fields'))
return;

bh_add_custom_menu_fields(array(
'excerpt' => array(
'description' => '摘要',
'type' => 'textarea',
)));
}
?>

存取欄位

存取您所增加的欄位最簡單的方法是使用以下方式:

$menu = '選單名稱';
$posts = wp_get_nav_menu_items($menu);
foreach ($posts as $p) {
$myitem = get_post_meta($p->ID, '_menu_item_youritem', true);
// 將 $myitem 傳回字串,
// 可以直接使用 "echo"
}

如果您喜歡使用選單位置來獲取選單名稱,可以使用以下程式碼替換上述程式碼的第一行:

$locations = get_nav_menu_locations();
$menu = $locations['位置名稱'];

如果您喜歡交換選單,選單位置會很有用。

不幸的是,這些範例並不能使用 WordPress 內建的選單巡覽器。要使用它們,您需要建立一個自訂的 Walker_Nav_Menu 類別,使用以下程式碼來存取自訂欄位(非常簡化的範例,需要擴展完整的 walker 巨集功能,網上有自訂巡覽欄教學):

class mywalker extends Walker_Nav_Menu {
function start_el(&$output, $item, $depth, $args) {
echo $item->custom_field
}
}

重要的是,欄位存放在第二變數上,它的行為像是一個物件。custom_field 部分是您所命名的欄位名稱,橫線用底線取代(以允許名稱可用作存取器)。

注意

這個外掛並不會自己做什麼,它只提供一個 API。

原文外掛簡介

This plugin provides an API which allows the developer of a site to add custom fields on the default menu editor.
Example Initialisation
array(
'description' => 'Excerpt',
'type' => 'textarea',
)));
}
?>

Accessing the fields
The easiest way to access the field(s) you’ve added is to use something along the lines of:
$menu = 'menuName';
$posts = wp_get_nav_menu_items($menu);
foreach ($posts as $p) {
$myitem = get_post_meta($p->ID, '_menu_item_youritem', true);
// do with $myitem what you like - it should be a string,
// so the simplest thing is to "echo" it
}

you can use menu locations to get the menu name if you prefer – replace the first line above with:
$locations = get_nav_menu_locations();
$menu = $locations['locationName'];

menu locations are useful if you like to swap your menus about.
Unfortunately these examples don’t allow the use of wordpress’ inbuilt menu walkers. To use those you will need to create a custom walker_nav_menu class and access the custom fields with something along the lines of (very stripped down example will need fleshing out for full walker functionality – there are tutorials on the net for custom nav walkers):
class mywalker extends Walker_Nav_Menu {
function start_el(&$output, $item, $depth, $args) {
echo $item->custom_field
}
}

The important bit here is that the field is placed on the second variable which behaves like an object. the custom_field part is the name you gave your field with dashes replaced with underscores (to allow the name to be used in an accessor).
NOTE
This plugin does nothing by itself. It provides an API only.

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Custom Menu Fields」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


0.1 | 0.2 | trunk |

延伸相關外掛(你可能也想知道)

  • Advanced Custom Fields (ACF®) 》Advanced Custom Fields 可以讓 WordPress 網站成為一個完整的內容管理系統,提供您所有工具以更好管理您的數據。, 使用 Advanced Custom Fields 外掛,完全...。
  • CMB2 》CMB2 是一個開發人員的工具包,用於在 WordPress 上構建 metabox,自定義字段和表單,可以讓您震撼。輕鬆管理帖子、條款、用戶、評論的元數據,或創建自定義...。
  • Advanced Custom Fields: Extended 》🚀 全方位增強套件,可改進WordPress和Advanced Custom Fields。此外掛旨在提供一個強大的管理框架,涵蓋了眾多改進和優化。, 此外掛需要至少 ACF Pro 5.8。,...。
  • Dynamic Conditions 》Dynamic Conditions 是一個 Elementor 外掛,加入了條件邏輯來顯示或隱藏不同元素。該外掛將條件添加到動態標籤中,以顯示/隱藏小工具或區塊。, 此外掛需要 E...。
  • ACF Photo Gallery Field 》t; 'Status', , 'name' => 'status', , 'choices' => array(, 'public' => 'Public', , 'private' => ...。
  • Custom Field Suite 》Custom Field Suite (CFS) 讓您為文章添加自定義欄位。它輕量級且經過過往使用者的測試(很難出現錯誤)。, 需要了解的事項, , 我們不提供支援。, 這是一個免...。
  • Custom Field Template 》「Custom Field Template 外掛」在「編寫文章/頁面」時,新增自訂欄位的預設設定。這個模板格式基本上跟「rc:custom_field_gui 外掛」差不多,不同處在於:, ...。
  • Custom Block Builder – Lazy Blocks 》WordPress 自訂區塊外掛程式, ★★★★★, 開發商使用於 WordPress 自訂區塊的魔法棒。我們創建了 Lazy Blocks WordPress 外掛程式,協助每位開發商取得他們需要的...。
  • Secure Custom Fields 》總結:SCF 是一款能夠擴展 WordPress 功能的外掛,使其成為一個靈活的內容管理工具。透過 SCF,管理自定義數據變得簡單高效。, , 1. 為什麼 SCF 是一個靈活的...。
  • Genesis Custom Blocks 》Genesis Custom Blocks 為 WordPress 開發人員提供了必要的工具,以應對現代 WordPress 「區塊先行」的實境。, WordPress 區塊編輯器(又稱 Gutenberg)為我...。
  • Product Input Fields for WooCommerce 》Product Input Fields for WooCommerce 插件可讓您在 WooCommerce 產品的前端添加自定義輸入字段,以供顧客在添加產品到購物車之前填寫。, 可以全域性地(即...。
  • BuddyPress Xprofile Custom Field Types 》BuddyPress Xprofile Custom Field Types 插件為 BuddyPress 資料檔案新增了一些必要的欄位類型。, BuddyPress Xprofile Custom Field Types 與 BP Profile S...。
  • PixFields 》使用 PixFields,您可以擁有自訂欄位的視覺化管理工具。, 注意:此外掛不會新增任何樣式至自訂欄位的輸出結果,它僅僅新增了元數據(metadata)並提供了一種覆...。
  • NextGEN Custom Fields 》這款外掛是為了將自訂欄位加到卓越且受歡迎的 NextGEN Gallery 外掛而開發。只需輸入新欄位的名稱,從「輸入」、「文字區域」或「下拉式選單」中選擇,就會自...。
  • Just Custom Fields 》Just Custom Fields(即自定義欄位)增加了在文章、頁面(與其他自定義文章類型)和分類中添加附加欄位的功能。安裝後,您將看到一個簡單的設置頁面,易於使...。

文章
Filter
Apply Filters
Mastodon