[WordPress] 外掛分享: Page navigation by menu

首頁外掛目錄 › Page navigation by menu
全新外掛
安裝啟用
尚無評分
104 天前
最後更新
問題解決
WordPress 4.9+ PHP 5.6+ v1.1.1 上架:2022-07-07

內容簡介

此外掛可提供頁面導覽功能,類似於內建函式 the_posts_navigation() 用於文章的功能。
導覽的頁面會依照所提供的選單篩選(預設為主選單)及與選單項目相同的順序排序。
預設會使用主選單,但可以呼叫其他選單的函式,以使用其他選單進行顯示。

使用方式
基本

只需要安裝此外掛,並在 php 模板中呼叫 the_pages_navigation() 即可。同樣有一個 get_the_pages_navigation() 函式,可回傳相同內容的字串。
這些函式可提供額外的參數(都是選項),如下:
* $menu – 要顯示頁面的選單 ID、捷徑、名稱或物件(WP_Term)
* $start_position – 從選單中的哪個位置開始導覽
? $end_position – 停止顯示導覽的選單位置

進階

有一些可用的篩選器可以協助自訂此外掛的輸出。

更換選單篩選器

apply_filters('page_nav_menu', $default_menu)

篩選用於導覽的選單。

$default_menu – 要顯示頁面的選單 ID、捷徑、名稱或物件(WP_Term)

箭頭篩選器

apply_filters( 'page_nav_left_arrow', $HTML )
apply_filters( 'page_nav_right_arrow', $HTML )

篩選箭頭輸出。

$HTML – 箭頭的 HTML 碼,可編碼為 SVG、img 等等格式。

篩選輸出

apply_filters( 'arrow_wrapper', $HTML_output, $left, $enabled, $output_image, $output_link, $output_div, $output_text )

篩選整個 HTML 輸出。

$HTML_output – 正如其名
$left – 輸出用於左邊(上一頁)的箭頭
$enabled – 启用了该侧的导航
$output_image – 箭头图像的 HTML
$output_link – 箭头链接的 URL
$output_div – 箭头旁边的文字的包含器
$output_text – 箭头旁边的文字

篩選範例
add_filter( 'page_nav_left_arrow', function() {
return '<svg width="53" height="32" viewBox="0 0 53 32" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M51.77 15.994H1M16.622 31L1 15.998 16.622 1v30z" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';
} );

外掛標籤

開發者團隊

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

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

原文外掛簡介

Plugin to support navigation by pages – similar to built in function the_posts_navigation() for posts.
Pages in navigation are filtered by provided menu (Primary menu by default) and sorted in the same order as in menu.
By default, main menu is used, but different menu could be used by calling function for displaying with different menu as parameter.
Disclaimer!
This plugin works only with classic themes. With FSE themes it will not work, since it depends on classic menus.
Usage
Basic
Just install and call the_pages_navigation() in your php template. There is also a get_the_pages_navigation() function which returns string with same content.
Arguments to these functions could be supplied, all optional.
* $menu – a menu ID, slug, name, or object (WP_Term) for which to show pages
* $start_position – start position from which position in menu to start navigation
? $end_position – to which position in menu to show navigation
Advanced
There are filters that can help to customize plugin output.
Change menu filter
apply_filters('page_nav_menu', $default_menu)

Filters menu used for navigation.

$default_menu – a menu ID, slug, name, or object (WP_Term)

Arrow filters
apply_filters( 'page_nav_left_arrow', $HTML )
apply_filters( 'page_nav_right_arrow', $HTML )

Filters arrow output.

$HTML – HTML of arrow, coded as SVG, img or something else.

Filter output
apply_filters( 'arrow_wrapper', $HTML_output, $left, $enabled, $output_image, $output_link, $output_div, $output_text )

Filters whole HTML output.

$HTML_output – as the name says
$left – output is for left side (previous)
$enabled – navigation on that side is enabled
$output_image – html of arrow image
$output_link – URL of link to which arrow leads
$output_div – wrapper of text besides arrow
$output_text – text besides arrow

Examples of filtering
add_filter( 'page_nav_left_arrow', function() {
return '';
} );

延伸相關外掛

文章
Filter
Apply Filters
Mastodon