[WordPress] 外掛分享: Codepress Menu

前言介紹

  • 這款 WordPress 外掛「Codepress Menu」是 2012-08-16 上架。
  • 目前有 100 個安裝啟用數。
  • 上一次更新是 2013-08-02,距離現在已有 4292 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
  • 外掛最低要求 WordPress 3.1 以上版本才可以安裝。
  • 有 2 人給過評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

tschutter | davidmosterd |

外掛標籤

nav | menu | walker | submenu | navigation |

內容簡介

使用原生的wp_nav_menu() 功能。 添加參數到 wp_nav_menu() 以啟用功能。
同時,在 WordPress 管理員中附帶了一鍵刪除菜單項目的功能。使用屏幕選項開啟或關閉。方便實用。

範例

以下程式碼將從活動分支和其中 2 級子選單中獲取第一個子選單 (菜單 + 子選單 + 子選單):

wp_nav_menu( array(
'level' => 2,
'depth' => 3
));

只顯示當前分支:

wp_nav_menu( array(
'level' => 1
));

用於不同情況下的簡單使用:

// 在頁首顯示第一層
wp_nav_menu( array(
'depth' => 1
));

// 在其他地方顯示當前分支中的第一個子選單
wp_nav_menu( array(
'depth' => 2,
'level' => 2
));

另一個功能是它對於賦予菜單項目的 CSS 類的控制。您可能會面臨無法更改的 CSS 選擇器。
可以在您的 functions.php 中使用 codepress_menu_filter_classes 過濾器來設置類屬性:

/**
* 更改菜單項目的類
*
* @param array $classes 顯示當前類別清單
* @param object $item 當前菜單項目
* @param array $items 當前項目的列表(每一層)
* @param integer $k $items 中當前項目的索引鍵
*/
function codepress_menu_item_classes( $classes, $item, $items, $k ) {
// 標記第一個項目
if ( reset( $items ) == $items[ $k ] )
$classes[] = 'first';

// 標記最後一個項目
if ( end( $items ) == $items[ $k ] )
$classes[] = 'last';

// 將 WordPress 預設的 'current-menu-item' 類映射到 'active'
if ( in_array( 'current-menu-item', $classes ) )
$classes[] = 'active';

return $classes;
}
add_filter( 'codepress_menu_item_classes', 'codepress_menu_item_classes', 10, 4 );

簡單菜單刪除

它會在 WordPress 中附帶一鍵刪除菜單項目的功能。
這個功能是從我們的 Simple Menu Delete 外掛整合而來,稍作改進:

使用屏幕選項開啟或關閉。
顯示與 WordPress 方式的刪除連結更接近。
現在與內嵌刪除連結完全相同。

原文外掛簡介

Uses the native wp_nav_menu(). Add parameters to the wp_nav_menu() to enable functionality.
Also, ships with one-click delete menu-items in the WordPress admin. Turned off or on using the screen-options. Sweet.
Examples
This will get the first sub-menu from the active branch and 2 levels beyond (menu + sub-menu + sub-menu):
wp_nav_menu( array(
'level' => 2,
'depth' => 3
));

Show the current branch only:
wp_nav_menu( array(
'level' => 1
));

Aimed on simple use in various use cases:
// display first level in the header
wp_nav_menu( array(
'depth' => 1
));

// display first sub-menu from the current branch somewhere else
wp_nav_menu( array(
'depth' => 2,
'level' => 2
));

Another feature is it’s control over the css classes that are given to a menu-item. You might be faced with css selectors
which you cannot change. The ‘codepress_menu_filter_classes’ filter can be used in your functions.php to set the class property:
/**
* Change the classes of a menu item
*
* @param array $classes List current classes
* @param object $item Current menu item
* @param array $items Current list of items (per level)
* @param integer $k Key of the current item in $items
*/
function codepress_menu_item_classes( $classes, $item, $items, $k ) {
// mark the first item
if ( reset( $items ) == $items[ $k ] )
$classes[] = 'first';

// mark the last item
if ( end( $items ) == $items[ $k ] )
$classes[] = 'last';

// map the WordPress default 'current-menu-item' class to 'active'
if ( in_array( 'current-menu-item', $classes ) )
$classes[] = 'active';

return $classes;
}
add_filter( 'codepress_menu_item_classes', 'codepress_menu_item_classes', 10, 4 );

Simple Menu Delete
It ships with one-click delete menu-items within WordPress.
This functionality was integrated from our Simple Menu Delete plugin and enhanced a bit:

Turned off or on using the screen-options.
Display is more in line with WordPress’s way of delete-links.
Works exactly the same now as the nested delete-link which is a click further inside the menu item.

各版本下載點

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

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


2.0 | 2.1 | 2.2 | 2.3 | 2.1.1 | 2.1.2 | 2.2.1 | 2.2.2 | 2.3.1 | 2.3.2 | trunk |

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

暫無相關外掛推薦。

文章
Filter
Apply Filters
Mastodon