[WordPress] 外掛分享: Default Theme Pages

首頁外掛目錄 › Default Theme Pages
WordPress 外掛 Default Theme Pages 的封面圖片
10+
安裝啟用
尚無評分
4944 天前
最後更新
問題解決
WordPress 3.0+ v0.4 上架:2012-06-17

內容簡介

此外掛旨在為模板開發人員提供便利
版本 0.4 中的新功能

在每個 $default_theme_pages 項目中添加「物件」(頁面物件),以便快速存取。
將所有預設頁面添加到 WordPress 工具列中「站台名稱」內,以增強使用者體驗。

使用方法

將下列程式碼加入 functions.php:

global $default_theme_pages;
$default_theme_pages = array(
array(
'name' => 'home', // 模板設置的初始頁面 slug / id - 存取函數
'title' => '首頁', // 頁面標題
'option' => 'page_on_front', // 選項頁面 ID(將頁面 ID 存儲在選項中,在這些情況下僅使用)
'description' => '首頁' // 描述
),
array(
'name' => 'blog',
'title' => '博客',
'option' => 'page_for_posts',
'description' => '博客'
),
array(
'name' => 'contact',
'title' => '聯絡我們',
'description' => '聯絡表單頁面'
)
);

提示

自動建立完頁面之後,您可以自由更改它們的標題和 slug。
若新增自訂頁面選項:「page_on_front」和「page_for_posts」,您將會阻止首頁和博客頁面。

模板設置

您可以依據 ID 或名稱(在 $default_theme_pages 全域變數中設置)進行模板設置,例如:

page-131.php 或 page-contact.php(如果您在 $default_theme_pages 全域變數中將其定義為 pagename,變更頁面 slug 後仍可正常運作)。

用以下程式碼偵測是否在該頁面:

dtp_is_page('contact')

取得預設頁面 ID:

$page_id = dtp_get_page_id('contact');

此方法較 get_page_by_path 更快,因為頁面 ID 儲存在全域變數中。

外掛標籤

開發者團隊

⬇ 下載最新版 (v0.4) 或搜尋安裝

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

原文外掛簡介

This plugin is intended to be useful for template developers
New in version 0.4

added ‘object’ (page object) in every $default_theme_pages item for fast access.
added all default pages to wp toolbar, inside ‘site name’, to increase user experience.

How to use
Add this code in your functions.php.
global $default_theme_pages;
$default_theme_pages = array(
array(
'name' => 'home', // initial slug page / id for templating - access functions
'title' => 'Homepage', // page title
'option' => 'page_on_front', // option page id ( stores the page id in an option, use only in theese cases)
'description' => 'homepage' // description
),
array(
'name' => 'blog',
'title' => 'Blog',
'option' => 'page_for_posts',
'description' => 'blog'
),
array(
'name' => 'contact',
'title' => 'Contact me!',
'description' => 'Contact form page'
)
);

Tips

After the pages are created automatically, you can change their title and slug without problem.
If you add an option names: page_on_front and page_for_posts, you will block the home-page and the blog-page on your site.

Templating
You can template using ID or name (setted up in $default_theme_pages global variable ), something like:
page-131.php or page-contact.php (If you change the page slug, this will still work because ‘contact’ was defined as pagename if $default_theme_pages global variable).
For detect if you’re in that page:
dtp_is_page('contact')

Getting a default page id:
$page_id = dtp_get_page_id('contact');

This method is more quick than get_page_by_path because page ID is stored on global variable.

延伸相關外掛

文章
Filter
Apply Filters
Mastodon