外掛說明
想要將佈景主題中的舊式 [← 較舊的文章 | 較新的文章 →] 連結取代為頁面連結嗎?
這個外掛提供了可產生精美分頁連結的 wp_pagenavi()
範本標籤。
使用方式
針對使用中的佈景主題,必須找到呼叫 next_posts_link()
及 previous_posts_link()
函式的程式碼,並將他們取代為外掛指定的程式碼。
在 Twentyten 佈景主題中,程式碼看起來大致如下:
<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentyten' ) ); ?></div>
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentyten' ) ); ?></div>
請將上述兩行程式碼取代為以下程式碼:
<?php wp_pagenavi(); ?>
針對多頁分頁連結,請搜尋類似以下的程式碼:
<?php wp_link_pages( ... ); ?>
並取代為下列程式碼:
<?php wp_pagenavi( array( 'type' => 'multipart' ) ); ?>
前往 WordPress 管理後台→[設定]→[PageNavi] 進行設定。
變更 CSS
如需變更 WP-PageNavi 的 CSS 樣式,請從外掛目錄複製 pagenavi-css.css
至使用中的佈景主題的目錄中,然後修改佈景主題目錄中的副本檔案。使用這個方式,便不會在這個外掛更新時遺失之前進行的變更。
另外,網站管理員可以在外掛設定頁取消核取 [使用 pagenavi-css.css],並直接在使用中的佈景主題的 style.css 檔案中加入相關樣式。
變更類別名稱
以下列出的篩選器,均可用於變更指派給頁面導覽元素的預設類別名稱。
篩選器
wp_pagenavi_class_pages
wp_pagenavi_class_first
wp_pagenavi_class_previouspostslink
wp_pagenavi_class_extend
wp_pagenavi_class_smaller
wp_pagenavi_class_page
wp_pagenavi_class_current
wp_pagenavi_class_larger
wp_pagenavi_class_nextpostslink
wp_pagenavi_class_last
篩選器使用方式
// Simple Usage - 1 callback per filter
add_filter('wp_pagenavi_class_previouspostslink', 'theme_pagination_previouspostslink_class');
add_filter('wp_pagenavi_class_nextpostslink', 'theme_pagination_nextpostslink_class');
add_filter('wp_pagenavi_class_page', 'theme_pagination_page_class');
function theme_pagination_previouspostslink_class($class_name) {
return 'pagination__control-link pagination__control-link--previous';
}
function theme_pagination_nextpostslink_class($class_name) {
return 'pagination__control-link pagination__control-link--next';
}
function theme_pagination_page_class($class_name) {
return 'pagination__current-page';
}
// More Concise Usage - 1 callback for all filters
add_filter('wp_pagenavi_class_previouspostslink', 'theme_pagination_class');
add_filter('wp_pagenavi_class_nextpostslink', 'theme_pagination_class');
add_filter('wp_pagenavi_class_page', 'theme_pagination_class');
function theme_pagination_class($class_name) {
switch($class_name) {
case 'previouspostslink':
$class_name = 'pagination__control-link pagination__control-link--previous';
break;
case 'nextpostslink':
$class_name = 'pagination__control-link pagination__control-link--next';
break;
case 'page':
$class_name = 'pagination__current'
break;
}
return $class_name;
}
開發工作
致謝名單
- 這個外掛採用了來自 Flaticon 的 SimpleIcon 所創作的圖示。
贊助開發工作
開發者用了許多時間建立外掛,並加以更新、維護及進行技術支援,如果喜歡這個外掛並贊助幾美元給開發者,開發者會非常感激。沒有贊助亦無妨,這個外掛可供網站隨時使用,不須有任何負擔。
螢幕擷圖
常見問題集
-
外掛啟用錯誤:「Parse error: syntax error, unexpected…」
-
請確認網站主機是否執行 PHP 5。最簡單的確認方式是在 wp-config.php 加入以下程式碼 (加在檔案開頭
<?php
標籤後方):var_dump(PHP_VERSION);
-
前往第 2 頁後,發現與第 1 頁相同的文章!
-
這是因為使用
query_posts()
的方式有誤。請參考〈使用 query_posts() 的正確方式〉一文。 -
可以,請參考這份教學文件。
-
如何不套用外掛設定頁面中的設定?
-
如果網站使用了多語系外掛,網站便不太需要套用外掛設定頁中的相關本地化字串值。
請在對應的檔案中加入類似下方的程式碼。
<?php wp_pagenavi( array( 'options' => PageNavi_Core::$options->get_defaults() ) ); ?>
使用者評論
參與者及開發者
變更記錄
2.94.5
- FIXED: WP SCB Framework now uses init hook again
2.94.4
- FIXED: Revert WP SCB Framework to use plugins_loaded hook
2.94.3
- FIXED: Update WP SCB Framework to fix load_textdomain_just_in_time warning
- FIXED: Remove load_plugin_textdomain since it is no longer needed since WP 4.6
2.94.2
- FIXED: load_plugin_textdomain to be called during init
2.94.1
- FIXED: PHP 8.2 warnings
2.94.0
- NEW: Add args param on wp_pagenavi filter. Props @asadowski10
- NEW: Improve accessibility of nav links. Props @carlabobak
2.93.4
- FIXED: Update SCB Framework To Support PHP 8
2.93.3
- FIXED: Update SCB Framework To Remove contextual_help
2.93.2
- NEW: Bumped to WordPress 5.4
- FIXED: Ensure Action Links is always an array
2.93.1
- FIXED: Duplicated Settings Saved admin_notices
2.93
- Remove screen_icon from SCB.
2.92
- Add title attr to pages link. Props @Mahjouba91.
2.91
- Validate text option against kses
- Update SCB Framework
2.90
- Remove po/mo files from the plugin
- Use translate.wordpress.org to translate the plugin
2.89.1
- FIXED: before and after args
2.89
- NEW: wrapper_tag option to allow other HTML tag besides DIV and wrapper_class option to allow other class name besides wp-pagenavi. Props @Mahjouba91.
2.88
- NEW: Added filters for altering class names. Props @bookwyrm
2.87
- NEW: Uses WordPress native uninstall.php
2.86
- NEW: Bump to 4.0
- NEW: Added rel=next and rel=previous
2.85
- FIXED: “Use pagenavi-css.css” & “Always Show Page Navigation” in the options are not being saved
2.84
- FIXED: Updated scb framework to fix scbAdminPage incompatible error
2.83
- added ‘echo’ parameter
- added Estonian and Bengali translations
- updated scbFramework
2.82
- fixed prev/next links not appearing in some conditions
- added Hebrew, Georgian and Azerbaijani translations
- updated scbFramework
2.81
- require an explicit type; fixes bugs with multipart pages
2.80
- support for multi-part pages and user queries
- moved prev/next links before/after first/last links
- more info
2.74 (2011-02-17)
- added ‘smaller’ and ‘larger’ classes
- added $query arg to wp_pagenavi()
- updated translations
- more info