[WordPress] 外掛分享: Advanced Custom Fields : CPT Options Pages

首頁外掛目錄 › Advanced Custom Fields : CPT Options Pages
WordPress 外掛 Advanced Custom Fields : CPT Options Pages 的封面圖片
2,000+
安裝啟用
★★★★★
5/5 分(7 則評價)
1075 天前
最後更新
問題解決
WordPress 3.0+ v2.0.9 上架:2016-07-07

內容簡介

這是一個針對 ACF Options 的小型附加外掛程式。為每個自訂文章類型添加 ACF 定位。

大版本 2 中的新功能!
重要!
升級到 v2+ 後,您必須重新連接欄位群組至選項頁面。

現在您可以啟用/停用自訂文章類型,並為每個自訂文章類型創建自訂選項頁面。
預設情況下,選項頁面啟用於所有自訂文章類型。

用法

ACF 外掛程式 的預設函數(get_field、the_field 等)可用來從自訂文章類型選項頁面載入值,但必須帶有第二個參數以定位自訂文章類型的選項。

這與傳遞 $post_id 參數以定位特定文章物件類似。

所需的 $post_id 參數是包含 cpt_ 和 CPT 名稱的字串,格式如下:"cpt_{CPT_NAME}",對於子頁面,可以在創建子頁面時複製生成的 ID。

範例

在範例中,自訂文章類型名稱為 projects。

那麼,讓我們開始吧!

顯示欄位

<p><?php the_field('field_name', 'cpt_projects'); ?></p>

和子頁面的欄位

<p><?php the_field('field_name', 'cpt_projects_testpage'); ?></p>

擷取欄位

<?php
$field = get_field('field_name', 'cpt_projects');
// 執行 $field
?>

顯示子欄位

<?php if( have_rows('repeater_name', 'cpt_projects') ): ?>
<ul>
<?php while( have_rows('repeater_name', 'cpt_projects') ): the_row(); ?>
<li><?php the_sub_field('the_title'); ?></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>

使用縮碼顯示

[acf field="field_name" post_id="cpt_projects"]

請閱讀關於 ACF 縮碼 的文檔。

自定義
function cpt_projects_customize($cptmenu) {
$cptmenu['page_title'] = 'Dev Custom title';
$cptmenu['menu_title'] = 'Dev Custom title';
return $cptmenu;
}

add_filter('cpt_projects_acf_page_args', 'cpt_projects_customize');

請勿忘記將 cpt_projects_ 替換為您的自訂文章類型名稱 🙂
僅適用於一級選項頁面,不適用於子頁面。

捐贈

支援此外掛程式

授權

版權所有 (c) 2021,Tusko Trush

要求

您必須購買 ACF PRO 或 ACF 選項頁面外掛程式。

翻譯

qTranslate-XT

此外掛程式與 ACF qTranslate 相容並包含在其中。
就這樣!

qTranslate-X

如果您正在使用 qTranslate-X,您必須安裝 ACF qTranslate。

WPML/Polylang

如果您正在使用 WPML 或 Polylang,您必須將常數 ICL_LANGUAGE_CODE 添加到 post_id 中,

外掛標籤

開發者團隊

⬇ 下載最新版 (v2.0.9) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Advanced Custom Fields : CPT Options Pages」→ 直接安裝(推薦)

原文外掛簡介

Small addon for ACF Options. Adds ACF location for each custom post type.
New feature in the major version 2!
Important!
After update to v2+ you must reconnect Field Groups to Options Pages
Now you can activate/deactivate CPTs and create custom options pages for each CPT.
By default, options pages are activated for all custom post types.
Usage
The default functions of ACF plugin (get_field, the_field, etc.) can be used to load values from a CPT Options Pages, but second parameter is required to target the CPT options.
This is similar to passing through a $post_id parameter to target a specific post object.
The $post_id parameter needed is a string containing the cpt_ and CPT name in the following format; "cpt_{CPT_NAME}" and for subpages you can copy generated ID while creating subpages.
Examples

In examples Custom Post Type name is projects.

So, let’s go!
Display a field

and the subpage’s field

Retrieve a field

Display a sub field

Display with shortcode
[acf field="field_name" post_id="cpt_projects"]

Please read documentation about shortcodes with ACF

Customization
function cpt_projects_customize($cptmenu) {
$cptmenu['page_title'] = 'Dev Custom title';
$cptmenu['menu_title'] = 'Dev Custom title';
return $cptmenu;
}

add_filter('cpt_projects_acf_page_args', 'cpt_projects_customize');

Don’t forget to replace cpt_projects_ to your custom post type name 🙂
It works only for first level options pages, not for subpages.
Donate
Support plugin
License
Copyright (c) 2023, Tusko Trush
Requirements
You must buy ACF PRO or ACF Options Page Addon.
Translation
qTranslate-XT
This plugin is compatible and has included ACF qTranslate.
Just enjoy!
qTranslate-X
If you are using Qtranslate-X, you must install ACF qTranslate.
WPML/Polylang
If you are using WPML or Polylang, you must add constant ICL_LANGUAGE_CODE to post_id,
for example: get_field('archive_title', 'cpt_projects_' . ICL_LANGUAGE_CODE).

延伸相關外掛

文章
Filter
Mastodon