iamntz/carbon-fields-urlpicker

Carbon Fields 扩展,添加 URL 选择器字段类型。

3.0.10 2023-03-10 07:33 UTC

This package is auto-updated.

Last update: 2024-09-10 10:38:45 UTC


README

(这是Carbon Fields插件的一个扩展:Carbon Fields)

您可以通过composer安装它

composer require iamntz/carbon-fields-urlpicker --prefer-dist

如果您从源安装,请确保您还运行了npm installnpm 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

示例

注册字段

这应该放在您的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>

请注意,blank字段将返回01,具体取决于“在新标签页中打开链接”旁边的复选框是否被勾选。

觉得这个有用吗?

您可以获取托管服务(并获得10美元信用额度!)捐赠购买礼物