內容簡介
這個外掛是為了已經存在的 Advanced Custom Fields 外掛而開發的,它增加了一種新的欄位類型,稱為「Link Picker」,讓用戶可以輸入網址或從現有頁面中選擇。它是 WYSIWYG 欄位編輯器中包含的連結選擇器的薄包裝。
此外掛程式是從 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
使用方式
在前端輸出連結選擇時,有三個物件元素可用:
url - 頁面的網址
title - 如有輸入,連結的標題
target - 可以是空字符串或「_blank」,取決於用戶是否勾選了在新視窗/標籤中打開連結的方塊。
範例程式碼:
$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"
}
外掛標籤
開發者團隊
② 後台搜尋「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
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.
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"
}
