內容簡介
這個外掛是針對已經廣泛使用的Advanced Custom Fields(高級自訂欄位)外掛的附加外掛,它添加了一種名為「Link Picker」的新欄位類型,允許用戶輸入 URL 或從現有頁面中進行選擇。它是圍繞著所包含的所見即所得欄位編輯器中的連接選擇器形成的一層薄薄的封裝。
這個版本的外掛是從 https://github.com/BIOSTALL/ACF-Link-Picker-Field 所帶有相同名稱的外掛中派生而來的。它的版本在 https://github.com/ahebrank/ACF-Link-Picker-Field 上進行了寄存,問題和 PR 應該在該處提交。
注意:在使用此附加外掛之前,必須安裝Advanced Custom Fields外掛。
相容性
這個 ACF 欄位類型相容於:
ACF 5
ACF 4
ACF 4 的支援已經被棄用,新的外掛功能通常不會與 ACF 4 版本相容。
用法
在前端輸出連接選擇時,您將有三個對象元素可用:
url - 頁面的 URL
title - 所選連結的標題(如果有)
target - 將是空白字符串或 _blank,取決於用戶是否勾選了在新視窗/分頁中打開連結的框框。
postid - 不作為 wp_link 的一部分,這是嘗試查找所選鏈接的文章 ID 的 ajax hack。如果找不到文章 ID,則會返回 0。
代碼示例:
$mylink = get_field('mylink');
var_dump($mylink);
輸出內容為:
array(3) {
["url"]=>
string(31) "http://mysite.com/selected/url/"
["title"]=>
string(10) "Link Title"
["target"]=>
string(6) "_blank"
["postid"]=>
int 2231
}
外掛標籤
開發者團隊
② 後台搜尋「Advanced Custom Fields: Link Picker Field」→ 直接安裝(推薦)
原文外掛簡介
This add on for the already established Advanced Custom Fields plugin adds a new field type called ‘Link Picker’ which allows the user to enter a URL, or select from the existing pages. It is a thin wrapper around the link selector included with the WYSIWYG field editor.
This plugin is forked from the plugin of the same name hosted at https://github.com/BIOSTALL/ACF-Link-Picker-Field. This version is hosted at https://github.com/ahebrank/ACF-Link-Picker-Field and issues and PRs should be submitted there.
Note: Advanced Custom Fields must be installed for this add-on to work.
Compatibility
This ACF field type is compatible with:
ACF 5
ACF 4
ACF 4 support is deprecated, and new plugin features will generally not work with ACF 4.
Usage
When outputting the link selection on the front end, you will have three object elements available:
url – The URL of the page
title – The title of the link, if entered
target – Will be either a blank string or ‘_blank’, depending on whether the user has ticked the box for the link to open in a new window/tab.
postid – Not available as part of wp_link, this is an ajax hack to attempt to look up the post ID of a selected link. This will return 0 if the post ID was not found.
Code example:
$mylink = get_field('mylink');
var_dump($mylink);
Outputs:
array(3) {
["url"]=>
string(31) "http://mysite.com/selected/url/"
["title"]=>
string(10) "Link Title"
["target"]=>
string(6) "_blank"
["postid"]=>
int 2231
}
