3615yeye / carbon-fields-urlpicker
Carbon Fields 扩展,添加了 URL 选择器字段类型。
3.0.1
2021-11-04 15:48 UTC
This package is not auto-updated.
Last update: 2024-09-21 03:26:03 UTC
README
警告:我只是为了在我自己的项目中使用这个包而分叉,不会降低其他依赖的稳定性。并不打算保持稳定。
(这是 Carbon Fields 插件的扩展)
composer require 3615yeye/carbon-fields-urlpicker
(首先,请确保你在 composer.json
中设置了 "minimum-stability": "dev"
)
或者通过安装为 WP 插件(尽管推荐使用 composer;作为插件安装可能会引发错误)。
返回值
该字段将返回一个包含以下值的关联数组
url: the actual URL
anchor: the text anchor (might be blank)
blank: wether the link should open in a new window or not
演示
https://img.iamntz.com/jing/video_2017-09-01__12_22.mp4
示例
注册字段
这应该放在你的 functions.php
中,就像其他 Carbon Fields 字段一样。唯一不同的是类型是 urlpicker
。
use Carbon_Fields\Container; use Carbon_Fields\Field; add_action( 'carbon_fields_register_fields', 'crb_url_picker_test' ); function crb_url_picker_test() { Container::make( 'post_meta', 'URL Picker Test' ) ->add_fields( array( Field::make( 'urlpicker', 'crb_my_link', 'URL Picker Test' ) ->set_help_text( "This is a test of the URL picker." ) )); }
使用字段值
<?php $my_link = carbon_get_the_post_meta( 'crb_my_link' ); ?> <a href="<?= $my_link[url] ?>"<?= ( $my_link[blank] ? ' target="_blank"' : '') ?>><?= $my_link[anchor] ?></a>
请注意,anchor
字段将返回 0
或 1
,具体取决于“在新标签页中打开链接”旁边的复选框是否勾选。