前言介紹
- 這款 WordPress 外掛「WAJ Admin Menu」是 2018-11-22 上架。
- 目前尚無安裝啟用數,是個很新的外掛。如有要安裝使用,建議多測試確保功能沒問題!
- 上一次更新是 2019-05-07,距離現在已有 2187 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
- 外掛最低要求 WordPress 4.9.8 以上版本才可以安裝。
- 外掛要求網站主機運作至少需要 PHP 版本 7.0 以上。
- 尚未有人給過這款外掛評分。
- 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。
外掛協作開發者
waughjai |
外掛標籤
nav | html | admin menu | autogenerate |
內容簡介
在WordPress的「外觀」>「選單」中建立選單並生成對應的HTML清單。
可以自訂元素的類別(class)和ID,方便網頁設計,並可輕鬆加入「跳至內容」的連結,以提供給螢幕閱讀器使用者使用。
使用方式
由於在WordPress管理後台使用時需要先建立選單,然後再在模板檔案中引用,因此盡量使用 WPAdminMenuManager 單例(singleton)類別的靜態方法來處理管理選單。
首先,在管理頁面載入前,呼叫 WPAdminMenuManager 的「createAdminMenu」方法,必填的參數為選單的slug和標題,第三個參數則是其他屬性的雜湊表(hash map),可視為是選單的選項。這個步驟可以讓 WordPress後台的「外觀」>「選單」中出現該選單。
接著可以使用模板檔案或是 WordPress 內容編輯器中的 shortcode 來印出選單。
= PHP
使用模板檔案印出選單,只需要使用 WPAdminMenuManager 類別的「printAdminMenu」方法,必填參數為該管理選單的slug(在建立選單時設定)及一個可選的屬性雜湊表,若想要在不同類別的元素中以不同的樣式印出同一個選單時可使用。
= shortcode
想要透過_shortcode印出選單,可以使用 [admin-menu slug=”%slug%”],可選的屬性可以覆蓋建立選單時的設定。
WPAdminMenuManager還有兩種範本,分別是 header 和 footer ,只需要呼叫 WPAdminMenuManager::createHeaderMenu() 或 WPAdminMenuManager::createFooterMenu(),在必要時使用 WPAdminMenuManager::printHeaderMenu() 或 WPAdminMenuManager::printFooterMenu(),或是使用 shortcode [header-nav] 或 [footer-nav] 即可。
如果嘗試印出還未建立的選單,則不會顯示任何輸出。
管理選單的合法屬性(所有屬性皆為可選的):
“nav”:代表包含所有元素的 nav 元素。應包含一個帶有 class 或 id 屬性的雜湊表,或兩者皆有。
“ul”:代表 ul 元素。應與 “nav” 相同。
“li”:代表 li 元素。應包含一個帶有 class 屬性的雜湊表。
“a”:代表 a 元素。應與 “li” 相同。
“subnav”:代表多級選單的子 ul 元素。應與 “li” 相同。
“subitem”:代表多級選單的子 li 元素。應與 “li” 相同。
“sublink”:代表多級選單的子 a 元素。應與 “li” 相同。
“parent-link”:代表包含子選單的頂層 li 元素的子元素 a。應與 “li” 相同。
“skip-to-content”:自動加入「跳至內容」的連結。應設定為一個字串,表示此連結要前往的錨點(不包含#),沒有設置的話就不會顯示「跳至內容」連結。
簡碼屬性也可以作為這些:
nav-class
nav-id
ul-class
ul-id
li-class
a-class
subnav-class
subitem-class
sublink-class
parent-link-class
skip-to-content
範例
// functions.php
declare( stric
原文外掛簡介
Creates menu in WordPress’s Appearances -> Menus & generates list HTML from it.
Allows custom-set classes & IDs for elements for easier styling & has easy way to automatically add “Skip to Content” link for screen-reader users.
Usage
Since admin menus need to be created before initialization to work in the WordPress admin & used later in template files to print, admin menu objects are handled through static methods in the WPAdminMenuManager singleton class.
1st, before admin loads, call the “createAdminMenu” method on WPAdminMenuManager with a slug & title as the 1st 2 mandatory, & a hash map o’ other attributes as an optional 3rd argument. This will make the menu appear under the given name in Appearances -> Menus in the WordPress admin.
Then you can print the menu through PHP in template files or shortcodes in WordPress content editors.
= PHP
To use through PHP, just call the “printAdminMenu” method on the WPAdminMenuManager class with the mandatory argument o’ the slug representing the admin you want to print ( given when creating the menu earlier ) & an optional hash map o’ attributes to o’erride the ones given when creating the menu, if you want to print the same menu in different places with different element classes, for instance.
= Shortcodes
To print through shortcodes, just use the shortcode [admin-menu slug=”%slug%”], with optional extra attributes to o’erride the attributes given when creating the menu.
WPAdminMenuManager also has 2 templates for easier creation o’ admin menus, a header & footer template. Just call WPAdminMenuManager::createHeaderMenu() or WPAdminMenuManager::createFooterMenu() respectively to create them & either call WPAdminMenuManager::printHeaderMenu() or WPAdminMenuManager::printFooterMenu() or use the shortcodes [header-nav] or [footer-nav].
If you try to print a menu that hasn’t been created yet, it will print nothing.
Valid attributes for admin menus ( all are optional ):
“nav”: represents the nav element that holds everything. Should hold a hash map with either a class or id attribute, or both.
“ul”: represents ul element. Should hold the same as “nav”.
“li”: represents li element. Should hold a hash map with a class attribute.
“a”: represents a element. Should hold the same as “li”.
“subnav”: represents child ul elements for multilevel menus. Should hold the same as “li”.
“subitem”: represents child li elements for multilevel menus. Should hold the same as “li”.
“sublink”: represents child a elements for multilevel menus. Should hold the same as “li”.
“parent-link”: represents a elements in top-level li elements that hold child navs. Should hold the same as “li”.
“skip-to-content”: automatically adds “skip to content” link. Should be a string that will be the anchor ( without the # ) that the “skip to content” link should go to. If not added, “skip to content” link will not be added.
Shortcode attributes that act as these:
nav-class
nav-id
ul-class
ul-id
li-class
a-class
subnav-class
subitem-class
sublink-class
parent-link-class
skip-to-content
Example
// functions.php
declare( strict_types = 1 );
namespace MyTheme
{
use WaughJ\WPAdminMenuManager\WPAdminMenumanager;
// Make sure this is initialized early,
// so WordPress Admin knows that this menu is set up.
WPAdminMenuManager::createAdminMenu
(
'extra-menu',
'Extra Menu',
[
'nav' =>
[
'class' => 'extra-menu-nav',
'id' => 'extra-menu-nav'
],
'ul' =>
[
'class' => 'extra-menu-list',
'id' => 'extra-menu-list'
],
'li' =>
[
'class' => 'extra-menu-item'
],
'a' =>
[
'class' => 'extra-menu-link'
],
'subnav' =>
[
'class' => 'extra-menu-subnav'
],
'subitem' =>
[
'class' => 'extra-menu-subitem'
],
'sublink' =>
[
'class' => 'extra-menu-sublink'
],
'parent-link' =>
[
'class' => 'extra-menu-parent-link'
],
'skip-to-content' => 'top'
]
);
}
// inc/header.php
各版本下載點
- 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
- 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「WAJ Admin Menu」來進行安裝。
(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。
1.0.0 | 1.1.0 | 1.1.2 | 1.1.3 | 1.1.4 | 1.2.0 | 1.2.1 | trunk |
延伸相關外掛(你可能也想知道)
Black Studio TinyMCE Widget 》此外掛添加了一個新的 Visual Editor 小工具類型,讓您能夠在側邊欄中輕鬆地插入豐富的文字和媒體對象。使用 Black Studio TinyMCE Widget 時,您將能夠使用W...。
Shortcoder — Create Shortcodes for Anything 》Shortcoder 外掛可讓您建立 HTML、JavaScript、CSS 和其他代碼片段的自訂捷徑。現在,這些捷徑可以在文章/頁面中使用,並且該片段將取代其位置。, ✍ 輕鬆建立...。
Simple Sitemap – Create a Responsive HTML Sitemap 》簡單網站地圖 (Simple Sitemap) 是 WordPress 上最受歡迎的 HTML 網站地圖,現在使用更加簡單。你可以在文章編輯器中直接建立和預覽網站地圖! 不再需要使用難...。
Mammoth .docx converter 》Mammoth 設計用於將 .docx 文件(如 Microsoft Word、Google Docs 和 LibreOffice 創建的文件)轉換為 HTML。Mammoth 旨在利用文檔中的語義信息生成簡單和清...。
Code Embed 》注意: WordPress 5.0 及以上版本的使用者請查看常見問題以了解如何在區塊編輯器中使用此外掛。, Code Embed 外掛允許您在文章中嵌入程式碼(JavaScript 和 H...。
Raw HTML 》is capability is only granted to administrators. If you’re not an admin, you will need to ask them to add it to your role., Raw HTML is not r...。
PHP Everywhere 》注意:此外掛更新至 3.0.0 版本是一項重大變更,將移除 [php_everywhere] 短代碼和小工具。請透過外掛設定頁面中的升級嚮導,將原本的代碼轉換為 Gutenberg ...。
WP Super Minify • Minify, Compress and Cache HTML, CSS & JavaScript 》這個外掛可以在需要時結合、縮小和緩存內聯的 JavaScript 和 CSS 文件,以加快頁面加載速度,並使用Minify PHP Framework。, 啟用此外掛後,您會發現您的 HTM...。
Minify HTML 》你可以在這個免費的測試網站試用這個外掛 => https://demo.tastewp.com/minify-html-markup, 有時候你可能會注意到自己網站的 HTML 標籤看起來較為混亂和...。
Allow HTML in Category Descriptions 》當您在類別描述文本區添加文字並保存類別時,WordPress會運行內容過濾器,剝除除最基本格式標籤以外的所有內容。, 這個外掛程式可以禁用具有必要權限的角色的...。
Advance Custom HTML 》這是一款用來專業編寫 HTML 代碼的高級 HTML 編輯器,提供不同的樣式、縮排與更多功能。, Advance Custom HTML 是一款功能強大、彈性十足的區塊外掛,讓您可...。
Kwayy HTML Sitemap 》Kwayy HTML Sitemap可以為您的網站地圖頁面生成HTML(而非XML)網站地圖。這個外掛不僅會顯示頁面和文章,還會顯示其他自定義的文章類型,例如產品等。您還可...。
Export WP Page to Static HTML/CSS 》Export WP Page to Static HTML/CSS 外掛是一個靜態 HTML 網站或頁面產生器,它能幫助您將您的 WordPress 網站或頁面轉換成靜態 HTML 網站,讓您可以將其託管...。
Code Widget 》Code Widget 是一個簡單的小工具,允許您插入任意的文字/HTML,執行 PHP 程式碼或 Short Code。此小工具解析 PHP 程式碼為簡單文字等等。, 只有擁有未過濾的 ...。
Preserved HTML Editor Markup Plus 》這個外掛保留了使用者在 TinyMCE 編輯器中產生的 HTML 標記。不像其他外掛,這個外掛允許開發人員在 HTML 標籤中工作,同時讓終端使用者在所見即所得的視覺化...。