metabolism / carbon-fields-urlpicker
Carbon Fields 扩展,添加了 URL 选择器字段类型。
3.0.10
2024-01-23 09:40 UTC
README
(这是 Carbon Fields 插件的扩展)
您可以通过 composer 安装它
composer require iamntz/carbon-fields-urlpicker --prefer-dist
如果您从源代码安装,请确保运行 npm install
和 npm run production
以编译资源。
返回值
该字段将返回以下值的关联数组
url: the actual URL
anchor: the text anchor (might be blank)
blank: wether the link should open in a new window or not
示例
注册字段
与其它 Carbon Fields 字段一样,此代码应放在您的 functions.php
文件中。唯一不同的是,类型为 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>
请注意,blank
字段将返回 0
或 1
,具体取决于“在新标签页中打开链接”旁边的复选框是否勾选。