在上一篇討論如何使用 WordPress 分頁導航 (Pagination) 的文章中, 我們知道, 如果要將一篇長的文章, 只要在需要分頁的地方, 插入以下的代碼便是了:

<!–nextpage–>

但是, 如果文章真的很長, 要在 WordPress 的 HTML 編輯器內搜尋需要分頁的地方實不容易。你可能會問: 「為什麼不在WordPress 編輯器工具列上新增一個分頁導航按鈕, 那麼便可以在 WordPress 的可視編輯器內插入以上的分頁導航代碼?」

我想, WordPress 可能為了保持簡潔的 WordPress 編輯器, 沒有將所有可用的按鈕放在工具列上。 試想想, 如果將所有可能使用的按鈕都放在工具列上, 情況真的很不理想, 其實很多按鈕根本很少用或不會用。

當然, 最理想就是由博客決定, 將自己經常用的按鈕(例如:分頁導航) 加在WordPress 編輯器工具列上。不用擔心, WordPress 是容許這樣做的。

要在 WordPress 編輯器工具列上新增一個分頁導航按鈕十分容易。

1. 用 FTP 軟件 (例如 WS_FTP) 登入 WordPress 的網頁寄存户口。

2. 瀏覽至在使用的 WordPress 佈景主題 (例如: twentyten) 。

3.  每個 WordPress 佈景主題目錄內都有一個 functions.php 檔案, 我們就是要在這檔案內新增分頁導航按鈕的程式碼。

wordpress-add-pagination-button-to-editor-toolbar

4. 用文字編輯軟件 (Text Editor)  開啟上述 WordPress  的 functions.php 檔案。

5. 在 WordPress functions.php 檔案的最後加入以下的 程式碼, 這程式碼便是用作在 WordPress 編輯器工具列上新增一個分頁導航按鈕。

// ————————————————————————–
// Start Add NextPage Button
// ————————————————————————–
add_filter(‘mce_buttons’,’wysiwyg_editor’);
function wysiwyg_editor($mce_buttons) {
$pos = array_search(‘wp_more’,$mce_buttons,true);
if ($pos !== false) {
$tmp_buttons = array_slice($mce_buttons, 0, $pos+1);
$tmp_buttons[] = ‘wp_page’;
$mce_buttons = array_merge($tmp_buttons, array_slice($mce_buttons, $pos+1));
}
return $mce_buttons;
}
// ————————————————————————–
// End Add NextPage Button
// ————————————————————————–

如下圖:

wordpress-add-pagination-button-to-editor-toolbar

以上程式碼不是小弟寫的, 是在多月前在網上找到的。

6.  嘗試寫一篇新文章。Yeah! 在 WordPress 編輯器工具列上已經新增了一個分頁導航按鈕。

wordpress-add-pagination-button-to-editor-toolbar

現在可以很方便的在 WordPress 的可視編輯器內插入以上的分頁導航代碼了。

wordpress-add-pagination-button-to-editor-toolbar

現在 WordPress 編輯器的工具列上有了分頁導航按鈕, 我們可以很方便的做分頁了!