前言介紹
- 這款 WordPress 外掛「Navigable」是 2011-05-16 上架。
- 目前有 30 個安裝啟用數。
- 上一次更新是 2012-01-08,距離現在已有 4866 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
- 外掛最低要求 WordPress 3.0 以上版本才可以安裝。
- 有 1 人給過評分。
- 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。
外掛協作開發者
ainth |
外掛標籤
menus | subnav | sub-nav | navigation | menu templating |
內容簡介
概述
Navigable 是一個供模板開發人員使用的 WordPress 外掛程式。它提供了 WordPress wp_nav_menu() 函數的替代方案。優勢如下:
Navigable 提供一個可操作的資料結構,並且您可以在範本中掌握 100% 的標記控制權。
您可以確定導覽元素在啟用元素之前或之後發生。
具有彈性。需要將當前子導覽從主導覽列表中分開嗎?需要單獨顯示當前頁面所屬的任何導航層嗎?需要指定元素的子導航樹嗎?
需要:
PHP5
僅在 WordPress 3.1 上進行測試,但自它僅使用少量 WordPress 函數,所以可能也可以在以前的版本上運作。
使用方法
您需要首先實例化一個導航物件:
參數是 wp_get_nav_menu_items() 接受的任何引數。
或者,如果您想跳過自定義導航選單,只將所有頁面放入導航汁,則可以使用不同的類:
現在,您可以迭代:
- title; ?>
tree as $elem): ?>
如果一個元素有一個子導覽:
title; ?>
sub_nav): ?>
- title; ?>
sub_nav as $sub_elem): ?>
tree as $elem): ?>
如果您想要當前子導航樹(如果您需要在主導航循環之外使用此功能,這很有用):
current_sub_nav()): ?>
...
您可能需要顯示當前頁面所在的任何導覽層:
active_tier()): ?>
...
您可能需要特定元素的子導覽:
find_branch(74)): // 為元素 74 獲取子導覽? ?>
...
或者
find_branch('About Us', 'title')): ?>
...
您可能希望基於用戶所在的頁面標記哪些是活動的,如果您非常高級,您可能希望標記該元素之前和之後的元素:
...
<
原文外掛簡介
Overview
Navigable is a WordPress plugin for template developers. It gives you an alternative to WordPress’s wp_nav_menu() function. Advantages:
Navigable gives you a data structure to work with. You have 100% markup control, and it’s all in the templates.
You can determine if a nav element occurs before/after an active element.
Flexibility. Need the current sub-navigation separate from the main nav list? Need whichever navigation tier the current page is on all by itself? Need the sub nav tree of a specific element?
Requires:
PHP5
Only tested on WordPress 3.1, will likely work on much earlier versions since it only uses a few WordPress Functions
Usage
You need to instantiate a navigation object first:
The paramaters are any arguments accepted by wp_get_nav_menu_items().
Alternatively, if you want to skip a custom navigation menu and just have all pages thrown into a nav stew you can use a different class:
Now you can iterate:
-
tree as $elem): ?>
- title; ?>
If an element has a subnav:
-
tree as $elem): ?>
-
title; ?>
sub_nav): ?>-
sub_nav as $sub_elem): ?>
- title; ?>
If you want the current sub nav tree (useful if you need this outside the main nav loop):
current_sub_nav()): ?>
...
You might want whichever tier of navigation the current page is on:
active_tier()): ?>
...
You might want the sub-navigation of a particular element:
find_branch(74)): //get the subnav of element 74 ?>
...
or
find_branch('About Us', 'title')): ?>
...
You’ll probably want to mark which things are active based on which page the user is on. And if you’re very fancy you’ll want to mark the elements before and after that element:
...
title; ?>
...
No need to use echo – whatever string you pass to any of these functions will be echo as if by magic.
There’s a bunch more that operate in much the same way:
if_current($markup); // echo markup if this element is the current post
$elem->if_active($markup); // echo markup if element is active (both the direct parent and the current element are 'active')
$elem->if_active_parent($markup); // echo markup if element is a parent of the current element
$elem->if_before_active($markup); // echo markup if element is before an active element (both parents and current)
$elem->if_after_active($markup); // echo markup if element is after an active element (both parents and current)
?>
Here are the variables navigation elements have:
id; // In NavigableWP class, id of the nav menu item. In NavigableWPPages id of actual page
$elem->object_id; // In NavigableWP class, id of the page. In the NavigableWPPages class, same as id
$elem->order; // Not too useful. The menu order of the item
$elem->url; // Full url of the page/post.
$elem->title; // Name of the element.
$elem->parent_id; // ID of the parent of the element. Root elements have a parent id of 0.
$elem->slug; // The slug/url title/post_title of the element's page.
?>
Things to know
What page are you on? There’s two different things Navigable does to try to figure it out. The first is the obvious route, we just ask WordPress:
$current_post = get_queried_object()->ID;
This will work for pretty much everyone but didn’t quite work for me. If you use podscms or any other plugin that means that the page you’re on isn’t a WordPress post that strategy won’t work. So if that doesn’t work Navigable will assume you are using clean urls that correspond nicely to your navigation tree, and will mark as active the last most specific thing it can find in the nav tree. For example, suppose the request uri is: yoursite.com/about/stuff/andthings/my-pods-slug. The my-pods-slug is actually a podscms slug, so WordPress is confused. Navigable will iterate through the nav tree, looking for about. If it finds it, it will look into about‘s subnav if it has one and look for stuff, then again it will look for andthings. It will try to find my-pods-slug but can’t so it will assume andthings is the current post.
Motivation
Navigation in WordPress is handled like so:
Passing an array of arguments lets you control a lot of the markup that’s generated:
,
'menu' => ,
'container' => 'div',
'container_class' => 'menu-{menu slug}-container',
'container_id' => ,
'menu_class' => 'menu',
'menu_id' => ,
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => ,
'after' => ,
'link_before' => ,
'link_after' => ,
'depth' => 0,
'walker' => );
?>
I found this a bit unsatisfactory – I’d much rather have some kind of
data structure to work with that would let me iterate over nav elements
so I have complete control over the markup. I also needed to assign a
class to the nav element that comes before the active element and saw no
way to do that with the standard WordPress function. Finally, I needed
the sub navigation on its own, apart from the main nav listing, and saw
no way to do it.
The problem (thought it’s not a problem for most I bet) with the approach I’m taking with this plugin is of course that if you have a whole lot of sub navigation tiers your code is going to get quite messy. But then most designs aren’t going to support too many navigation tiers either, and if they did they’d likely need different classes and such to be able to support the design so this still works.
各版本下載點
- 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
- 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Navigable」來進行安裝。
(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。
0.34 | 0.36 | 0.37 | 0.38 | 0.39 | trunk |
延伸相關外掛(你可能也想知道)
Tomi Menu 》當頁面被創建/編輯時,若啟用,此外掛會自動將子頁面加入正確菜單中,並在需要移除時將頁面從原菜單中移除。, 使用說明, 只需在所選菜單中勾選“自動將新的頂...。